aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-03-02 14:01:40 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2003-03-02 14:01:40 +0000
commite589ede6fdc3f0f3f70be950bdd85d996eb19eca (patch)
tree9009d19b2288a0d97ad1295a9a9cf0e04c193766 /libjava/java/awt
parent37db829b936aa6483eff60a7522e34ad6dcecb79 (diff)
downloadgcc-e589ede6fdc3f0f3f70be950bdd85d996eb19eca.zip
gcc-e589ede6fdc3f0f3f70be950bdd85d996eb19eca.tar.gz
gcc-e589ede6fdc3f0f3f70be950bdd85d996eb19eca.tar.bz2
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
Diffstat (limited to 'libjava/java/awt')
-rw-r--r--libjava/java/awt/Component.java88
-rw-r--r--libjava/java/awt/Container.java21
-rw-r--r--libjava/java/awt/ContainerOrderFocusTraversalPolicy.java54
-rw-r--r--libjava/java/awt/EventQueue.java127
-rw-r--r--libjava/java/awt/ScrollPane.java37
5 files changed, 227 insertions, 100 deletions
diff --git a/libjava/java/awt/Component.java b/libjava/java/awt/Component.java
index 88f9181..c9afaa1 100644
--- a/libjava/java/awt/Component.java
+++ b/libjava/java/awt/Component.java
@@ -4075,46 +4075,62 @@ p * <li>the set of backward traversal keys
*/
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
* tend to create a lot of paint events that are adjacent but not
diff --git a/libjava/java/awt/Container.java b/libjava/java/awt/Container.java
index 91804d7..caffc50 100644
--- a/libjava/java/awt/Container.java
+++ b/libjava/java/awt/Container.java
@@ -45,6 +45,7 @@ import java.awt.peer.ComponentPeer;
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;
@@ -89,6 +90,7 @@ public class Container extends Component
/* Anything else is non-serializable, and should be declared "transient". */
transient ContainerListener containerListener;
+ transient PropertyChangeSupport changeSupport;
/**
* Default constructor for subclasses.
@@ -1125,12 +1127,27 @@ public class Container extends Component
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.
diff --git a/libjava/java/awt/ContainerOrderFocusTraversalPolicy.java b/libjava/java/awt/ContainerOrderFocusTraversalPolicy.java
index 71267a5..1042939 100644
--- a/libjava/java/awt/ContainerOrderFocusTraversalPolicy.java
+++ b/libjava/java/awt/ContainerOrderFocusTraversalPolicy.java
@@ -41,11 +41,15 @@ package java.awt;
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;
@@ -55,31 +59,77 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
*/
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;
}
diff --git a/libjava/java/awt/EventQueue.java b/libjava/java/awt/EventQueue.java
index 6b64fb7..90ba6ea 100644
--- a/libjava/java/awt/EventQueue.java
+++ b/libjava/java/awt/EventQueue.java
@@ -116,7 +116,8 @@ public class EventQueue
if (next_in != next_out)
return queue[next_out];
- else return null;
+ else
+ return null;
}
/**
@@ -142,7 +143,7 @@ public class EventQueue
{
AWTEvent qevt = queue[i];
if (qevt.id == id)
- return qevt;
+ return qevt;
}
return null;
}
@@ -159,7 +160,7 @@ public class EventQueue
if (next != null)
{
next.postEvent(evt);
- return;
+ return;
}
// FIXME: Security checks?
@@ -169,25 +170,25 @@ public class EventQueue
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;
@@ -198,15 +199,15 @@ public class EventQueue
{
/* 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();
}
@@ -237,8 +238,8 @@ public class EventQueue
synchronized (current)
{
- eq.postEvent(ie);
- current.wait();
+ eq.postEvent(ie);
+ current.wait();
}
Exception exception;
@@ -247,7 +248,9 @@ public class EventQueue
throw new InvocationTargetException(exception);
}
- /** @since JDK1.2 */
+ /**
+ * @since 1.2
+ */
public static void invokeLater(Runnable runnable)
{
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
@@ -264,22 +267,26 @@ public class EventQueue
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;
@@ -301,19 +308,19 @@ public class EventQueue
// 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;
+ }
}
}
@@ -328,22 +335,22 @@ public class EventQueue
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);
+ }
}
}
diff --git a/libjava/java/awt/ScrollPane.java b/libjava/java/awt/ScrollPane.java
index 9b8b82a..b5192f3 100644
--- a/libjava/java/awt/ScrollPane.java
+++ b/libjava/java/awt/ScrollPane.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.awt;
+import java.awt.event.MouseEvent;
import java.awt.peer.ScrollPanePeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.ComponentPeer;
@@ -105,6 +106,8 @@ private int scrollbarDisplayPolicy;
// Current scroll position
private Point scrollPosition = new Point(0, 0);
+private boolean wheelScrollingEnabled;
+
/*************************************************************************/
/*
@@ -153,6 +156,8 @@ ScrollPane(int scrollbarDisplayPolicy)
hAdjustable = new ScrollPaneAdjustable(Scrollbar.HORIZONTAL);
vAdjustable = new ScrollPaneAdjustable(Scrollbar.VERTICAL);
}
+
+ wheelScrollingEnabled = true;
}
/*************************************************************************/
@@ -470,5 +475,37 @@ paramString()
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