下面列出了javax.swing.JComponent#getLocationOnScreen ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void assertAbove(DockingWindowManager dwm, ComponentProvider p1, ComponentProvider p2) {
ComponentPlaceholder ph1 = dwm.getActivePlaceholder(p1);
ComponentPlaceholder ph2 = dwm.getActivePlaceholder(p2);
ComponentNode n1 = ph1.getNode();
ComponentNode n2 = ph2.getNode();
JComponent c1 = n1.getComponent();
JComponent c2 = n2.getComponent();
Point l1 = c1.getLocationOnScreen();
Point l2 = c2.getLocationOnScreen();
assertTrue(
"Provider is not above the other provider. " + p1.getName() + " / " + p2.getName(),
l1.y < l2.y);
}
private void assertTotheRight(DockingWindowManager dwm, ComponentProvider p1,
ComponentProvider p2) {
ComponentPlaceholder ph1 = dwm.getActivePlaceholder(p1);
ComponentPlaceholder ph2 = dwm.getActivePlaceholder(p2);
ComponentNode n1 = ph1.getNode();
ComponentNode n2 = ph2.getNode();
JComponent c1 = n1.getComponent();
JComponent c2 = n2.getComponent();
Point l1 = c1.getLocationOnScreen();
Point l2 = c2.getLocationOnScreen();
assertTrue("Provider is not to the right of the other provider. " + p1.getName() + " / " +
p2.getName(), l1.x > l2.x);
}
private void assertStacked(DockingWindowManager dwm, ComponentProvider... providers) {
Integer x = null;
Integer y = null;
for (ComponentProvider p : providers) {
ComponentPlaceholder ph = dwm.getActivePlaceholder(p);
ComponentNode n = ph.getNode();
JComponent c = n.getComponent();
Point l = c.getLocationOnScreen();
if (x == null) {
x = l.x;
y = l.y;
}
else {
assertEquals("Providers are not stacked together", x.intValue(), l.x);
assertEquals("Providers are not stacked together", y.intValue(), l.y);
}
}
}
/**
* Return true if the mouse is currently over the argument.
*/
protected boolean isRollover(JComponent jc) {
if (!jc.isShowing())
return false;
Point p = jc.getLocationOnScreen();
int w = jc.getWidth();
int h = jc.getHeight();
Point mouse = MouseInfo.getPointerInfo().getLocation();
return mouse.x >= p.x && mouse.y >= p.y && mouse.x < p.x + w
&& mouse.y < p.y + h;
}
/**
* zSetPopupLocation, This calculates and sets the appropriate location for the popup windows,
* for both the DatePicker and the TimePicker.
*/
static void zSetPopupLocation(CustomPopup popup, int defaultX, int defaultY, JComponent picker,
JComponent verticalFlipReference, int verticalFlipDistance, int bottomOverlapAllowed) {
// Gather some variables that we will need.
Window topWindowOrNull = SwingUtilities.getWindowAncestor(picker);
Rectangle workingArea = InternalUtilities.getScreenWorkingArea(topWindowOrNull);
int popupWidth = popup.getBounds().width;
int popupHeight = popup.getBounds().height;
// Calculate the default rectangle for the popup.
Rectangle popupRectangle = new Rectangle(defaultX, defaultY, popupWidth, popupHeight);
// If the popup rectangle is below the bottom of the working area, then move it upwards by
// the minimum amount which will ensure that it will never cover the picker component.
if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
popupRectangle.y = verticalFlipReference.getLocationOnScreen().y - popupHeight
- verticalFlipDistance;
}
// Confine the popup to be within the working area.
if (popupRectangle.getMaxX() > (workingArea.getMaxX())) {
popupRectangle.x -= (popupRectangle.getMaxX() - workingArea.getMaxX());
}
if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
popupRectangle.y -= (popupRectangle.getMaxY() - workingArea.getMaxY());
}
if (popupRectangle.x < workingArea.x) {
popupRectangle.x += (workingArea.x - popupRectangle.x);
}
if (popupRectangle.y < workingArea.y) {
popupRectangle.y += (workingArea.y - popupRectangle.y);
}
// Set the location of the popup.
popup.setLocation(popupRectangle.x, popupRectangle.y);
}
private void repaintBadge(JComponent field) {
Point p = field.getLocationOnScreen();
SwingUtilities.convertPointFromScreen(p, this);
int x = p.x - warningIcon.getWidth() / 2;
int y = (int) (p.y + field.getHeight() - warningIcon.getHeight() / 1.5);
repaint(x, y, warningIcon.getWidth(), warningIcon.getHeight());
}
public Point2D getAbsoluteLocation() {
Point2D result = null;
JComponent jc = getContainerResolve();
if (jc != null) {
result = new java.awt.Point(jc.getLocationOnScreen());
result.setLocation(result.getX() + getX(), result.getY() + getY());
}
return result;
}
public void atMouse(JComponent jComponent) {
Point myMouse = DisplayHelper.getMouseLocation();
Point myPoint = jComponent.getLocationOnScreen();
designAndGetJPopupMenu().show(jComponent, myMouse.x - myPoint.x, myMouse.y - myPoint.y);
}