aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@redhat.com>2004-02-04 20:43:32 +0000
committerGraydon Hoare <graydon@gcc.gnu.org>2004-02-04 20:43:32 +0000
commitcbc848da46639c42ceaf193ea8dab1cdeea02a6f (patch)
tree5f0aba49c0378ed3fa7fbc0f8e3945f14d78cae9 /libjava/java
parent7e63a64ecec9cbef98c626771e0c4d9ed0ff6347 (diff)
downloadgcc-cbc848da46639c42ceaf193ea8dab1cdeea02a6f.zip
gcc-cbc848da46639c42ceaf193ea8dab1cdeea02a6f.tar.gz
gcc-cbc848da46639c42ceaf193ea8dab1cdeea02a6f.tar.bz2
SwingUtilities.java: Many new functions.
2004-02-02 Graydon Hoare <graydon@redhat.com> * javax/swing/SwingUtilities.java: Many new functions. * java/awt/Container.java (LightweightDispatcher): Reimplement. * javax/swing/basic/BasicGraphicsUtils.java (getPreferredButtonSize): Start layout from top-left corner. From-SVN: r77271
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/awt/Container.java108
1 files changed, 52 insertions, 56 deletions
diff --git a/libjava/java/awt/Container.java b/libjava/java/awt/Container.java
index ed869e1..ff1dde1 100644
--- a/libjava/java/awt/Container.java
+++ b/libjava/java/awt/Container.java
@@ -52,6 +52,7 @@ import java.io.Serializable;
import java.util.EventListener;
import java.util.Set;
import javax.accessibility.Accessible;
+import javax.swing.SwingUtilities;
/**
* A generic window toolkit object that acts as a container for other objects.
@@ -1541,54 +1542,59 @@ class LightweightDispatcher implements Serializable
nativeContainer = c;
}
- void dispose()
- {
- }
-
void enableEvents(long l)
{
eventMask |= l;
}
- void mouseExit (MouseEvent me, int x, int y)
- {
- }
-
- void acquireComponentForMouseEvent (MouseEvent me)
+ void acquireComponentForMouseEvent(MouseEvent me)
{
int x = me.getX ();
int y = me.getY ();
-
Component candidate = mouseEventTarget;
-
- boolean candidate_is_container_with_children =
- ((candidate != null)
- && (candidate instanceof Container)
- && (((Container)candidate).getComponentCount () > 0));
-
- boolean candidate_does_not_contain_point =
- ((candidate != null)
- && (! candidate.contains (x - candidate.getX (),
- y - candidate.getY ())));
-
- if (candidate == null
- || candidate_is_container_with_children
- || candidate_does_not_contain_point)
+
+ while(candidate != null)
{
- // Try to reacquire.
- candidate = nativeContainer.findComponentAt (x, y);
+ if (candidate.isShowing())
+ {
+ // Convert our point to the candidate's parent's space.
+ Point cp = SwingUtilities.convertPoint(nativeContainer, x, y, candidate);
+
+ // If the event lands inside candidate, we have a hit.
+ if (candidate.contains(cp.x, cp.y))
+ {
+ // If candidate has children, we refine the hit.
+ if (candidate instanceof Container &&
+ ((Container)candidate).getComponentCount() > 0)
+ candidate = SwingUtilities.getDeepestComponentAt(candidate, cp.x, cp.y);
+ break;
+ }
+ }
+ // If candidate isn't showing or doesn't contain point, we back out a level.
+ candidate = candidate.getParent();
+ }
+
+ if (candidate == null)
+ {
+ // We either lost, or never had, a candidate; acquire from our native.
+ candidate =
+ SwingUtilities.getDeepestComponentAt(nativeContainer, x, y);
}
+
+ // If our candidate is new, inform the old target we're leaving.
if (mouseEventTarget != null
+ && mouseEventTarget.isShowing()
&& mouseEventTarget != candidate)
{
- int nx = x - mouseEventTarget.getX ();
- int ny = y - mouseEventTarget.getY ();
+ Point tp =
+ SwingUtilities.convertPoint(nativeContainer,
+ x, y, mouseEventTarget);
MouseEvent exited = new MouseEvent (mouseEventTarget,
MouseEvent.MOUSE_EXITED,
me.getWhen (),
me.getModifiers (),
- nx, ny,
+ tp.x, tp.y,
me.getClickCount (),
me.isPopupTrigger (),
me.getButton ());
@@ -1596,25 +1602,22 @@ class LightweightDispatcher implements Serializable
mouseEventTarget = null;
}
+ // If we have a candidate, maybe enter it.
if (candidate != null)
{
- // Possibly set new state.
if (candidate.isLightweight()
+ && candidate.isShowing()
&& candidate != nativeContainer
&& candidate != mouseEventTarget)
- {
-
+ {
mouseEventTarget = candidate;
-
- int nx = x - mouseEventTarget.getX ();
- int ny = y - mouseEventTarget.getY ();
-
- // If acquired, enter it.
+ Point cp = SwingUtilities.convertPoint(nativeContainer,
+ x, y, candidate);
MouseEvent entered = new MouseEvent (mouseEventTarget,
MouseEvent.MOUSE_ENTERED,
me.getWhen (),
me.getModifiers (),
- nx, ny,
+ cp.x, cp.y,
me.getClickCount (),
me.isPopupTrigger (),
me.getButton ());
@@ -1623,39 +1626,32 @@ class LightweightDispatcher implements Serializable
}
}
- boolean handleEvent (AWTEvent e)
+ boolean handleEvent(AWTEvent e)
{
- if ((eventMask & e.getID ()) == 0)
+ if ((eventMask & e.getID()) == 0)
return false;
if (e instanceof MouseEvent)
{
MouseEvent me = (MouseEvent) e;
- acquireComponentForMouseEvent (me);
+ acquireComponentForMouseEvent(me);
- // Avoid dispatching an ENTERED event twice
+ // Avoid dispatching an ENTERED event twice.
if (mouseEventTarget != null
+ && mouseEventTarget.isShowing()
&& e.getID() != MouseEvent.MOUSE_ENTERED)
{
- // Calculate point translation for the event target.
- // We use absolute location on screen rather than relative
- // location because the event target might be a nested child.
- Point parentLocation = nativeContainer.getLocationOnScreen();
- Point childLocation = mouseEventTarget.getLocationOnScreen();
- me.translatePoint(parentLocation.x - childLocation.x,
- parentLocation.y - childLocation.y);
-
- Component oldSource = (Component) me.getSource ();
- me.setSource (mouseEventTarget);
- mouseEventTarget.dispatchEvent (me);
- me.setSource (oldSource);
+ MouseEvent newEvt =
+ SwingUtilities.convertMouseEvent(nativeContainer, me,
+ mouseEventTarget);
+ mouseEventTarget.dispatchEvent(newEvt);
}
}
else if (e instanceof KeyEvent && focus != null)
{
- focus.processKeyEvent ((KeyEvent) e);
+ focus.processKeyEvent((KeyEvent) e);
}
-
+
return e.isConsumed();
}