Commit e589ede6 by Michael Koch Committed by Michael Koch

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.

From-SVN: r63663
parent 37db829b
2003-03-02 Michael Koch <konqueror@gmx.de> 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 * java/net/DatagramSocket.java
(closed): New member variable. (closed): New member variable.
(close): Use closed variable. (close): Use closed variable.
......
...@@ -4075,46 +4075,62 @@ p * <li>the set of backward traversal keys ...@@ -4075,46 +4075,62 @@ p * <li>the set of backward traversal keys
*/ */
void dispatchEventImpl(AWTEvent e) void dispatchEventImpl(AWTEvent e)
{ {
// Make use of event id's in order to avoid multiple instanceof tests. if (eventTypeEnabled (e.id))
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)
processEvent(e); 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 * 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 * areas is less than twice that of the sum of the areas. The X server
* tend to create a lot of paint events that are adjacent but not * tend to create a lot of paint events that are adjacent but not
......
...@@ -45,6 +45,7 @@ import java.awt.peer.ComponentPeer; ...@@ -45,6 +45,7 @@ import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer; import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer; import java.awt.peer.LightweightPeer;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Serializable; import java.io.Serializable;
...@@ -89,6 +90,7 @@ public class Container extends Component ...@@ -89,6 +90,7 @@ public class Container extends Component
/* Anything else is non-serializable, and should be declared "transient". */ /* Anything else is non-serializable, and should be declared "transient". */
transient ContainerListener containerListener; transient ContainerListener containerListener;
transient PropertyChangeSupport changeSupport;
/** /**
* Default constructor for subclasses. * Default constructor for subclasses.
...@@ -1125,12 +1127,27 @@ public class Container extends Component ...@@ -1125,12 +1127,27 @@ public class Container extends Component
throw new NullPointerException (); 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. // Hidden helper methods.
......
...@@ -41,11 +41,15 @@ package java.awt; ...@@ -41,11 +41,15 @@ package java.awt;
import java.io.Serializable; import java.io.Serializable;
/** /**
* STUB CLASS ONLY * @author Michael Koch
* @since 1.4
*/ */
public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
implements Serializable implements Serializable
{ {
/**
* Compatible to JDK 1.4+
*/
static final long serialVersionUID = 486933713763926351L; static final long serialVersionUID = 486933713763926351L;
private boolean implicitDownCycleTraversal = true; private boolean implicitDownCycleTraversal = true;
...@@ -55,31 +59,77 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy ...@@ -55,31 +59,77 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
*/ */
public ContainerOrderFocusTraversalPolicy() 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) public Component getComponentAfter(Container root, Component current)
{ {
if (root == null
|| current == null)
throw new IllegalArgumentException ();
return null; 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) public Component getComponentBefore(Container root, Component current)
{ {
if (root == null
|| current == null)
throw new IllegalArgumentException ();
return null; return null;
} }
/**
* Returns the first Component of root that should receive the focus.
*
* @exception IllegalArgumentException If root is null.
*/
public Component getFirstComponent(Container root) public Component getFirstComponent(Container root)
{ {
if (root == null)
throw new IllegalArgumentException ();
return null; return null;
} }
/**
* Returns the last Component of root that should receive the focus.
*
* @exception IllegalArgumentException If root is null.
*/
public Component getLastComponent(Container root) public Component getLastComponent(Container root)
{ {
if (root == null)
throw new IllegalArgumentException ();
return null; return null;
} }
/**
* Returns the default Component of root that should receive the focus.
*
* @exception IllegalArgumentException If root is null.
*/
public Component getDefaultComponent(Container root) public Component getDefaultComponent(Container root)
{ {
if (root == null)
throw new IllegalArgumentException ();
return null; return null;
} }
......
...@@ -116,7 +116,8 @@ public class EventQueue ...@@ -116,7 +116,8 @@ public class EventQueue
if (next_in != next_out) if (next_in != next_out)
return queue[next_out]; return queue[next_out];
else return null; else
return null;
} }
/** /**
...@@ -142,7 +143,7 @@ public class EventQueue ...@@ -142,7 +143,7 @@ public class EventQueue
{ {
AWTEvent qevt = queue[i]; AWTEvent qevt = queue[i];
if (qevt.id == id) if (qevt.id == id)
return qevt; return qevt;
} }
return null; return null;
} }
...@@ -159,7 +160,7 @@ public class EventQueue ...@@ -159,7 +160,7 @@ public class EventQueue
if (next != null) if (next != null)
{ {
next.postEvent(evt); next.postEvent(evt);
return; return;
} }
// FIXME: Security checks? // FIXME: Security checks?
...@@ -169,25 +170,25 @@ public class EventQueue ...@@ -169,25 +170,25 @@ public class EventQueue
while (i != next_in) while (i != next_in)
{ {
AWTEvent qevt = queue[i]; AWTEvent qevt = queue[i];
Object src; Object src;
if (qevt.id == evt.id if (qevt.id == evt.id
&& (src = qevt.getSource()) == evt.getSource() && (src = qevt.getSource()) == evt.getSource()
&& src instanceof Component) && src instanceof Component)
{ {
/* If there are, call coalesceEvents on the source component /* If there are, call coalesceEvents on the source component
to see if they can be combined. */ to see if they can be combined. */
Component srccmp = (Component) src; Component srccmp = (Component) src;
AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt); AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt);
if (coalesced_evt != null) if (coalesced_evt != null)
{ {
/* Yes. Replace the existing event with the combined event. */ /* Yes. Replace the existing event with the combined event. */
queue[i] = coalesced_evt; queue[i] = coalesced_evt;
return; return;
} }
break; break;
} }
if (++i == queue.length) if (++i == queue.length)
i = 0; i = 0;
} }
queue[next_in] = evt; queue[next_in] = evt;
...@@ -198,15 +199,15 @@ public class EventQueue ...@@ -198,15 +199,15 @@ public class EventQueue
{ {
/* Queue is full. Extend it. */ /* Queue is full. Extend it. */
AWTEvent[] oldQueue = queue; AWTEvent[] oldQueue = queue;
queue = new AWTEvent[queue.length * 2]; queue = new AWTEvent[queue.length * 2];
int len = oldQueue.length - next_out; int len = oldQueue.length - next_out;
System.arraycopy(oldQueue, next_out, queue, 0, len); System.arraycopy(oldQueue, next_out, queue, 0, len);
if (next_out != 0) if (next_out != 0)
System.arraycopy(oldQueue, 0, queue, len, next_out); System.arraycopy(oldQueue, 0, queue, len, next_out);
next_out = 0; next_out = 0;
next_in = oldQueue.length; next_in = oldQueue.length;
} }
notify(); notify();
} }
...@@ -237,8 +238,8 @@ public class EventQueue ...@@ -237,8 +238,8 @@ public class EventQueue
synchronized (current) synchronized (current)
{ {
eq.postEvent(ie); eq.postEvent(ie);
current.wait(); current.wait();
} }
Exception exception; Exception exception;
...@@ -247,7 +248,9 @@ public class EventQueue ...@@ -247,7 +248,9 @@ public class EventQueue
throw new InvocationTargetException(exception); throw new InvocationTargetException(exception);
} }
/** @since JDK1.2 */ /**
* @since 1.2
*/
public static void invokeLater(Runnable runnable) public static void invokeLater(Runnable runnable)
{ {
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
...@@ -264,22 +267,26 @@ public class EventQueue ...@@ -264,22 +267,26 @@ public class EventQueue
return (Thread.currentThread() == eq.dispatchThread); 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, * Allows a custom EventQueue implementation to replace this one.
* getNextEvent, and peekEvent are forwarded to the pushed queue until it * All pending events are transferred to the new queue. Calls to postEvent,
* is removed with a pop(). * getNextEvent, and peekEvent are forwarded to the pushed queue until it
* * is removed with a pop().
* @exception NullPointerException if newEventQueue is null. *
*/ * @exception NullPointerException if newEventQueue is null.
*/
public synchronized void push(EventQueue newEventQueue) public synchronized void push(EventQueue newEventQueue)
{ {
if (newEventQueue == null)
throw new NullPointerException ();
int i = next_out; int i = next_out;
while (i != next_in) while (i != next_in)
{ {
newEventQueue.postEvent(queue[i]); newEventQueue.postEvent(queue[i]);
next_out = i; next_out = i;
if (++i == queue.length) if (++i == queue.length)
i = 0; i = 0;
} }
next = newEventQueue; next = newEventQueue;
...@@ -301,19 +308,19 @@ public class EventQueue ...@@ -301,19 +308,19 @@ public class EventQueue
// occur. // occur.
synchronized (prev) synchronized (prev)
{ {
prev.next = null; prev.next = null;
} }
synchronized (this) synchronized (this)
{ {
int i = next_out; int i = next_out;
while (i != next_in) while (i != next_in)
{ {
prev.postEvent(queue[i]); prev.postEvent(queue[i]);
next_out = i; next_out = i;
if (++i == queue.length) if (++i == queue.length)
i = 0; i = 0;
} }
} }
} }
...@@ -328,22 +335,22 @@ public class EventQueue ...@@ -328,22 +335,22 @@ public class EventQueue
if (evt instanceof ActiveEvent) if (evt instanceof ActiveEvent)
{ {
ActiveEvent active_evt = (ActiveEvent) evt; ActiveEvent active_evt = (ActiveEvent) evt;
active_evt.dispatch(); active_evt.dispatch();
} }
else else
{ {
Object source = evt.getSource(); Object source = evt.getSource();
if (source instanceof Component) if (source instanceof Component)
{ {
Component srccmp = (Component) source; Component srccmp = (Component) source;
srccmp.dispatchEvent(evt); srccmp.dispatchEvent(evt);
} }
else if (source instanceof MenuComponent) else if (source instanceof MenuComponent)
{ {
MenuComponent srccmp = (MenuComponent) source; MenuComponent srccmp = (MenuComponent) source;
srccmp.dispatchEvent(evt); srccmp.dispatchEvent(evt);
} }
} }
} }
......
...@@ -38,6 +38,7 @@ exception statement from your version. */ ...@@ -38,6 +38,7 @@ exception statement from your version. */
package java.awt; package java.awt;
import java.awt.event.MouseEvent;
import java.awt.peer.ScrollPanePeer; import java.awt.peer.ScrollPanePeer;
import java.awt.peer.ContainerPeer; import java.awt.peer.ContainerPeer;
import java.awt.peer.ComponentPeer; import java.awt.peer.ComponentPeer;
...@@ -105,6 +106,8 @@ private int scrollbarDisplayPolicy; ...@@ -105,6 +106,8 @@ private int scrollbarDisplayPolicy;
// Current scroll position // Current scroll position
private Point scrollPosition = new Point(0, 0); private Point scrollPosition = new Point(0, 0);
private boolean wheelScrollingEnabled;
/*************************************************************************/ /*************************************************************************/
/* /*
...@@ -153,6 +156,8 @@ ScrollPane(int scrollbarDisplayPolicy) ...@@ -153,6 +156,8 @@ ScrollPane(int scrollbarDisplayPolicy)
hAdjustable = new ScrollPaneAdjustable(Scrollbar.HORIZONTAL); hAdjustable = new ScrollPaneAdjustable(Scrollbar.HORIZONTAL);
vAdjustable = new ScrollPaneAdjustable(Scrollbar.VERTICAL); vAdjustable = new ScrollPaneAdjustable(Scrollbar.VERTICAL);
} }
wheelScrollingEnabled = true;
} }
/*************************************************************************/ /*************************************************************************/
...@@ -470,5 +475,37 @@ paramString() ...@@ -470,5 +475,37 @@ paramString()
return(getClass().getName()); 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 } // class ScrollPane
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment