+2003-03-02 Michael Koch <konqueror@gmx.de>
+
+ * java/awt/Component.java
+ (eventTypeEnabled): New method.
+ (dispatchEventImpl): Moved checks for event to eventTypeEnabled.
+ * java/awt/Container.java
+ (changeSupport): New member variable.
+ (addPropertyChangeListener): New methods.
+ * java/awt/ContainerOrderFocusTraversalPolicy.java
+ (ContainerOrderFocusTraversalPolicy): Added comment.
+ (getComponentAfter): Throw exception, documentation added.
+ (getComponentBefore): Throw exception, documentation added.
+ (getFirstComponent): Throw exception, documentation added.
+ (getLastComponent): Throw exception, documentation added.
+ (getDefaultComponent): Throw exception, documentation added.
+ * java/awt/EventQueue.java: Reindented.
+ * java/awt/FocusTraversalPolicy.java:
+ (FocusTraversalPolicy): Added comment.
+ (getComponentAfter): Documentation added.
+ (getComponentBefore): Documentation added.
+ (getFirstComponent): Documentation added.
+ (getLastComponent): Documentation added.
+ (getDefaultComponent): Documentation added.
+ (getInitialComponent): Documentation added.
+ * java/awt/ScrollPane.java
+ (wheelScrollingEnabled): New member variable.
+ (ScrollPane): Initialize wheelScollingEnabled.
+ (eventTypeEnabled): New method.
+ (isWheelScrollingEnabled): New method.
+ (setWheelScrollingEnabled): New method.
+
2003-03-02 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
*/
void dispatchEventImpl(AWTEvent e)
{
- // Make use of event id's in order to avoid multiple instanceof tests.
- if (e.id <= ComponentEvent.COMPONENT_LAST
- && e.id >= ComponentEvent.COMPONENT_FIRST
- && (componentListener != null
- || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0))
- processEvent(e);
- else if (e.id <= KeyEvent.KEY_LAST
- && e.id >= KeyEvent.KEY_FIRST
- && (keyListener != null
- || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0))
- processEvent(e);
- else if (e.id <= MouseEvent.MOUSE_LAST
- && e.id >= MouseEvent.MOUSE_FIRST
- && (mouseListener != null
- || mouseMotionListener != null
- || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0))
- processEvent(e);
- else if (e.id <= FocusEvent.FOCUS_LAST
- && e.id >= FocusEvent.FOCUS_FIRST
- && (focusListener != null
- || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0))
- processEvent(e);
- else if (e.id <= InputMethodEvent.INPUT_METHOD_LAST
- && e.id >= InputMethodEvent.INPUT_METHOD_FIRST
- && (inputMethodListener != null
- || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0))
- processEvent(e);
- else if (e.id <= HierarchyEvent.HIERARCHY_LAST
- && e.id >= HierarchyEvent.HIERARCHY_FIRST
- && (hierarchyListener != null
- || hierarchyBoundsListener != null
- || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0))
- processEvent(e);
- else if (e.id <= PaintEvent.PAINT_LAST
- && e.id >= PaintEvent.PAINT_FIRST
- && (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0)
+ if (eventTypeEnabled (e.id))
processEvent(e);
}
+ /**
+ * Tells wether or not an event type is enabled.
+ */
+ boolean eventTypeEnabled (int type)
+ {
+ if (type > AWTEvent.RESERVED_ID_MAX)
+ return true;
+
+ switch (type)
+ {
+ case ComponentEvent.COMPONENT_HIDDEN:
+ case ComponentEvent.COMPONENT_MOVED:
+ case ComponentEvent.COMPONENT_RESIZED:
+ case ComponentEvent.COMPONENT_SHOWN:
+ return (componentListener != null
+ || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0);
+
+ case KeyEvent.KEY_PRESSED:
+ case KeyEvent.KEY_RELEASED:
+ case KeyEvent.KEY_TYPED:
+ return (keyListener != null
+ || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0);
+
+ case MouseEvent.MOUSE_CLICKED:
+ case MouseEvent.MOUSE_ENTERED:
+ case MouseEvent.MOUSE_EXITED:
+ case MouseEvent.MOUSE_PRESSED:
+ case MouseEvent.MOUSE_RELEASED:
+ return (mouseListener != null
+ || mouseMotionListener != null
+ || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0);
+
+ case FocusEvent.FOCUS_GAINED:
+ case FocusEvent.FOCUS_LOST:
+ return (focusListener != null
+ || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0);
+
+ case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
+ case InputMethodEvent.CARET_POSITION_CHANGED:
+ return (inputMethodListener != null
+ || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0);
+
+ case PaintEvent.PAINT:
+ case PaintEvent.UPDATE:
+ return (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0;
+
+ default:
+ return false;
+ }
+ }
+
/**
* Coalesce paint events. Current heuristic is: Merge if the union of
* areas is less than twice that of the sum of the areas. The X server
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
/* Anything else is non-serializable, and should be declared "transient". */
transient ContainerListener containerListener;
+ transient PropertyChangeSupport changeSupport;
/**
* Default constructor for subclasses.
throw new NullPointerException ();
}
- public void addPropertyChangeListener(PropertyChangeListener l)
+ public void addPropertyChangeListener (PropertyChangeListener listener)
{
+ if (listener == null)
+ return;
+
+ if (changeSupport == null)
+ changeSupport = new PropertyChangeSupport (this);
+
+ changeSupport.addPropertyChangeListener (listener);
}
- public void addPropertyChangeListener(String name, PropertyChangeListener l)
+ public void addPropertyChangeListener (String name,
+ PropertyChangeListener listener)
{
+ if (listener == null)
+ return;
+
+ if (changeSupport == null)
+ changeSupport = new PropertyChangeSupport (this);
+
+ changeSupport.addPropertyChangeListener (name, listener);
}
// Hidden helper methods.
import java.io.Serializable;
/**
- * STUB CLASS ONLY
+ * @author Michael Koch
+ * @since 1.4
*/
public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
implements Serializable
{
+ /**
+ * Compatible to JDK 1.4+
+ */
static final long serialVersionUID = 486933713763926351L;
private boolean implicitDownCycleTraversal = true;
*/
public ContainerOrderFocusTraversalPolicy()
{
- throw new Error("not implemented");
+ // Nothing to do here
}
+ /**
+ * Returns the Component that should receive the focus after current.
+ * root must be a focus cycle root of current.
+ *
+ * @exception IllegalArgumentException If root is not a focus cycle
+ * root of current, or if either root or current is null.
+ */
public Component getComponentAfter(Container root, Component current)
{
+ if (root == null
+ || current == null)
+ throw new IllegalArgumentException ();
+
return null;
}
+ /**
+ * Returns the Component that should receive the focus before current.
+ * root must be a focus cycle root of current.
+ *
+ * @exception IllegalArgumentException If root is not a focus cycle
+ * root of current, or if either root or current is null.
+ */
public Component getComponentBefore(Container root, Component current)
{
+ if (root == null
+ || current == null)
+ throw new IllegalArgumentException ();
+
return null;
}
+ /**
+ * Returns the first Component of root that should receive the focus.
+ *
+ * @exception IllegalArgumentException If root is null.
+ */
public Component getFirstComponent(Container root)
{
+ if (root == null)
+ throw new IllegalArgumentException ();
+
return null;
}
+ /**
+ * Returns the last Component of root that should receive the focus.
+ *
+ * @exception IllegalArgumentException If root is null.
+ */
public Component getLastComponent(Container root)
{
+ if (root == null)
+ throw new IllegalArgumentException ();
+
return null;
}
+ /**
+ * Returns the default Component of root that should receive the focus.
+ *
+ * @exception IllegalArgumentException If root is null.
+ */
public Component getDefaultComponent(Container root)
{
+ if (root == null)
+ throw new IllegalArgumentException ();
+
return null;
}
if (next_in != next_out)
return queue[next_out];
- else return null;
+ else
+ return null;
}
/**
{
AWTEvent qevt = queue[i];
if (qevt.id == id)
- return qevt;
+ return qevt;
}
return null;
}
if (next != null)
{
next.postEvent(evt);
- return;
+ return;
}
// FIXME: Security checks?
while (i != next_in)
{
AWTEvent qevt = queue[i];
- Object src;
- if (qevt.id == evt.id
- && (src = qevt.getSource()) == evt.getSource()
- && src instanceof Component)
- {
- /* If there are, call coalesceEvents on the source component
- to see if they can be combined. */
- Component srccmp = (Component) src;
- AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt);
- if (coalesced_evt != null)
- {
- /* Yes. Replace the existing event with the combined event. */
- queue[i] = coalesced_evt;
- return;
- }
+ Object src;
+ if (qevt.id == evt.id
+ && (src = qevt.getSource()) == evt.getSource()
+ && src instanceof Component)
+ {
+ /* If there are, call coalesceEvents on the source component
+ to see if they can be combined. */
+ Component srccmp = (Component) src;
+ AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt);
+ if (coalesced_evt != null)
+ {
+ /* Yes. Replace the existing event with the combined event. */
+ queue[i] = coalesced_evt;
+ return;
+ }
break;
- }
- if (++i == queue.length)
- i = 0;
+ }
+ if (++i == queue.length)
+ i = 0;
}
queue[next_in] = evt;
{
/* Queue is full. Extend it. */
AWTEvent[] oldQueue = queue;
- queue = new AWTEvent[queue.length * 2];
+ queue = new AWTEvent[queue.length * 2];
- int len = oldQueue.length - next_out;
- System.arraycopy(oldQueue, next_out, queue, 0, len);
- if (next_out != 0)
- System.arraycopy(oldQueue, 0, queue, len, next_out);
+ int len = oldQueue.length - next_out;
+ System.arraycopy(oldQueue, next_out, queue, 0, len);
+ if (next_out != 0)
+ System.arraycopy(oldQueue, 0, queue, len, next_out);
- next_out = 0;
- next_in = oldQueue.length;
+ next_out = 0;
+ next_in = oldQueue.length;
}
notify();
}
synchronized (current)
{
- eq.postEvent(ie);
- current.wait();
+ eq.postEvent(ie);
+ current.wait();
}
Exception exception;
throw new InvocationTargetException(exception);
}
- /** @since JDK1.2 */
+ /**
+ * @since 1.2
+ */
public static void invokeLater(Runnable runnable)
{
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
return (Thread.currentThread() == eq.dispatchThread);
}
- /** Allows a custom EventQueue implementation to replace this one.
- * All pending events are transferred to the new queue. Calls to postEvent,
- * getNextEvent, and peekEvent are forwarded to the pushed queue until it
- * is removed with a pop().
- *
- * @exception NullPointerException if newEventQueue is null.
- */
+ /**
+ * Allows a custom EventQueue implementation to replace this one.
+ * All pending events are transferred to the new queue. Calls to postEvent,
+ * getNextEvent, and peekEvent are forwarded to the pushed queue until it
+ * is removed with a pop().
+ *
+ * @exception NullPointerException if newEventQueue is null.
+ */
public synchronized void push(EventQueue newEventQueue)
{
+ if (newEventQueue == null)
+ throw new NullPointerException ();
+
int i = next_out;
while (i != next_in)
{
newEventQueue.postEvent(queue[i]);
- next_out = i;
- if (++i == queue.length)
- i = 0;
+ next_out = i;
+ if (++i == queue.length)
+ i = 0;
}
next = newEventQueue;
// occur.
synchronized (prev)
{
- prev.next = null;
+ prev.next = null;
}
synchronized (this)
{
- int i = next_out;
- while (i != next_in)
- {
+ int i = next_out;
+ while (i != next_in)
+ {
prev.postEvent(queue[i]);
- next_out = i;
- if (++i == queue.length)
- i = 0;
- }
+ next_out = i;
+ if (++i == queue.length)
+ i = 0;
+ }
}
}
if (evt instanceof ActiveEvent)
{
ActiveEvent active_evt = (ActiveEvent) evt;
- active_evt.dispatch();
+ active_evt.dispatch();
}
else
{
- Object source = evt.getSource();
+ Object source = evt.getSource();
- if (source instanceof Component)
- {
+ if (source instanceof Component)
+ {
Component srccmp = (Component) source;
- srccmp.dispatchEvent(evt);
- }
- else if (source instanceof MenuComponent)
- {
- MenuComponent srccmp = (MenuComponent) source;
- srccmp.dispatchEvent(evt);
- }
+ srccmp.dispatchEvent(evt);
+ }
+ else if (source instanceof MenuComponent)
+ {
+ MenuComponent srccmp = (MenuComponent) source;
+ srccmp.dispatchEvent(evt);
+ }
}
}
package java.awt;
+import java.awt.event.MouseEvent;
import java.awt.peer.ScrollPanePeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.ComponentPeer;
// Current scroll position
private Point scrollPosition = new Point(0, 0);
+private boolean wheelScrollingEnabled;
+
/*************************************************************************/
/*
hAdjustable = new ScrollPaneAdjustable(Scrollbar.HORIZONTAL);
vAdjustable = new ScrollPaneAdjustable(Scrollbar.VERTICAL);
}
+
+ wheelScrollingEnabled = true;
}
/*************************************************************************/
return(getClass().getName());
}
+ /**
+ * Tells wether or not an event is enabled.
+ *
+ * @since 1.4
+ */
+ public boolean eventTypeEnabled (int type)
+ {
+ if (type == MouseEvent.MOUSE_WHEEL)
+ return wheelScrollingEnabled;
+
+ return super.eventTypeEnabled (type);
+ }
+
+ /**
+ * Tells wether or not wheel scrolling is enabled.
+ *
+ * @since 1.4
+ */
+ public boolean isWheelScrollingEnabled ()
+ {
+ return wheelScrollingEnabled;
+ }
+
+ /**
+ * Enables/disables wheel scrolling.
+ *
+ * @since 1.4
+ */
+ public void setWheelScrollingEnabled (boolean enable)
+ {
+ wheelScrollingEnabled = enable;
+ }
} // class ScrollPane