Commit cbc848da by Graydon Hoare Committed by Graydon Hoare

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
parent 7e63a64e
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.
2004-02-04 Olga Rodimina <rodimina@redhat.com> 2004-02-04 Olga Rodimina <rodimina@redhat.com>
* java/awt/geom/AffineTransform.java: * java/awt/geom/AffineTransform.java:
......
...@@ -52,6 +52,7 @@ import java.io.Serializable; ...@@ -52,6 +52,7 @@ import java.io.Serializable;
import java.util.EventListener; import java.util.EventListener;
import java.util.Set; import java.util.Set;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.swing.SwingUtilities;
/** /**
* A generic window toolkit object that acts as a container for other objects. * A generic window toolkit object that acts as a container for other objects.
...@@ -1541,54 +1542,59 @@ class LightweightDispatcher implements Serializable ...@@ -1541,54 +1542,59 @@ class LightweightDispatcher implements Serializable
nativeContainer = c; nativeContainer = c;
} }
void dispose()
{
}
void enableEvents(long l) void enableEvents(long l)
{ {
eventMask |= l; eventMask |= l;
} }
void mouseExit (MouseEvent me, int x, int y) void acquireComponentForMouseEvent(MouseEvent me)
{
}
void acquireComponentForMouseEvent (MouseEvent me)
{ {
int x = me.getX (); int x = me.getX ();
int y = me.getY (); int y = me.getY ();
Component candidate = mouseEventTarget; Component candidate = mouseEventTarget;
boolean candidate_is_container_with_children = while(candidate != null)
((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)
{ {
// Try to reacquire. if (candidate.isShowing())
candidate = nativeContainer.findComponentAt (x, y); {
// 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 if (mouseEventTarget != null
&& mouseEventTarget.isShowing()
&& mouseEventTarget != candidate) && mouseEventTarget != candidate)
{ {
int nx = x - mouseEventTarget.getX (); Point tp =
int ny = y - mouseEventTarget.getY (); SwingUtilities.convertPoint(nativeContainer,
x, y, mouseEventTarget);
MouseEvent exited = new MouseEvent (mouseEventTarget, MouseEvent exited = new MouseEvent (mouseEventTarget,
MouseEvent.MOUSE_EXITED, MouseEvent.MOUSE_EXITED,
me.getWhen (), me.getWhen (),
me.getModifiers (), me.getModifiers (),
nx, ny, tp.x, tp.y,
me.getClickCount (), me.getClickCount (),
me.isPopupTrigger (), me.isPopupTrigger (),
me.getButton ()); me.getButton ());
...@@ -1596,25 +1602,22 @@ class LightweightDispatcher implements Serializable ...@@ -1596,25 +1602,22 @@ class LightweightDispatcher implements Serializable
mouseEventTarget = null; mouseEventTarget = null;
} }
// If we have a candidate, maybe enter it.
if (candidate != null) if (candidate != null)
{ {
// Possibly set new state.
if (candidate.isLightweight() if (candidate.isLightweight()
&& candidate.isShowing()
&& candidate != nativeContainer && candidate != nativeContainer
&& candidate != mouseEventTarget) && candidate != mouseEventTarget)
{ {
mouseEventTarget = candidate; mouseEventTarget = candidate;
Point cp = SwingUtilities.convertPoint(nativeContainer,
int nx = x - mouseEventTarget.getX (); x, y, candidate);
int ny = y - mouseEventTarget.getY ();
// If acquired, enter it.
MouseEvent entered = new MouseEvent (mouseEventTarget, MouseEvent entered = new MouseEvent (mouseEventTarget,
MouseEvent.MOUSE_ENTERED, MouseEvent.MOUSE_ENTERED,
me.getWhen (), me.getWhen (),
me.getModifiers (), me.getModifiers (),
nx, ny, cp.x, cp.y,
me.getClickCount (), me.getClickCount (),
me.isPopupTrigger (), me.isPopupTrigger (),
me.getButton ()); me.getButton ());
...@@ -1623,39 +1626,32 @@ class LightweightDispatcher implements Serializable ...@@ -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; return false;
if (e instanceof MouseEvent) if (e instanceof MouseEvent)
{ {
MouseEvent me = (MouseEvent) e; MouseEvent me = (MouseEvent) e;
acquireComponentForMouseEvent (me); acquireComponentForMouseEvent(me);
// Avoid dispatching an ENTERED event twice // Avoid dispatching an ENTERED event twice.
if (mouseEventTarget != null if (mouseEventTarget != null
&& mouseEventTarget.isShowing()
&& e.getID() != MouseEvent.MOUSE_ENTERED) && e.getID() != MouseEvent.MOUSE_ENTERED)
{ {
// Calculate point translation for the event target. MouseEvent newEvt =
// We use absolute location on screen rather than relative SwingUtilities.convertMouseEvent(nativeContainer, me,
// location because the event target might be a nested child. mouseEventTarget);
Point parentLocation = nativeContainer.getLocationOnScreen(); mouseEventTarget.dispatchEvent(newEvt);
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);
} }
} }
else if (e instanceof KeyEvent && focus != null) else if (e instanceof KeyEvent && focus != null)
{ {
focus.processKeyEvent ((KeyEvent) e); focus.processKeyEvent((KeyEvent) e);
} }
return e.isConsumed(); return e.isConsumed();
} }
......
...@@ -614,8 +614,8 @@ public class BasicGraphicsUtils ...@@ -614,8 +614,8 @@ public class BasicGraphicsUtils
b.getToolkit().getFontMetrics(b.getFont()), // see comment above b.getToolkit().getFontMetrics(b.getFont()), // see comment above
b.getText(), b.getText(),
b.getIcon(), b.getIcon(),
b.getVerticalAlignment(), SwingUtilities.TOP, // important:
b.getHorizontalAlignment(), SwingUtilities.LEFT, // large vrect, stick to the top left
b.getVerticalTextPosition(), b.getVerticalTextPosition(),
b.getHorizontalTextPosition(), b.getHorizontalTextPosition(),
viewRect, iconRect, textRect, viewRect, iconRect, textRect,
......
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