556 |
this.visible = visible; |
this.visible = visible; |
557 |
if (old != isVisible()) |
if (old != isVisible()) |
558 |
{ |
{ |
559 |
firePropertyChange("visible", old, isVisible()); |
firePropertyChange("visible", old, isVisible()); |
560 |
if (visible) |
if (visible) |
561 |
{ |
{ |
562 |
firePopupMenuWillBecomeVisible(); |
firePopupMenuWillBecomeVisible(); |
563 |
Container rootContainer = (Container) SwingUtilities.getRoot(invoker); |
Container rootContainer = (Container) SwingUtilities.getRoot(invoker); |
564 |
|
Dimension screenSize = getToolkit().getScreenSize(); |
565 |
|
|
566 |
|
boolean fit = true; |
567 |
|
Dimension size; |
568 |
|
|
569 |
boolean fit = true; |
// Determine the size of the popup menu |
570 |
Dimension size; |
if (this.getSize().width == 0 && this.getSize().width == 0) |
571 |
|
size = this.getPreferredSize(); |
572 |
|
else |
573 |
|
size = this.getSize(); |
574 |
|
|
575 |
// Determine the size of the popup menu |
if ((size.width > (rootContainer.getWidth() - popupLocation.x)) |
576 |
if (this.getSize().width == 0 && this.getSize().width == 0) |
|| (size.height > (rootContainer.getHeight() - popupLocation.y))) |
577 |
size = this.getPreferredSize(); |
fit = false; |
578 |
else |
if (lightWeightPopupEnabled && fit) |
579 |
size = this.getSize(); |
popup = new LightWeightPopup(this); |
580 |
|
else |
581 |
|
{ |
582 |
|
if (fit) |
583 |
|
popup = new MediumWeightPopup(this); |
584 |
|
else |
585 |
|
popup = new HeavyWeightPopup(this); |
586 |
|
} |
587 |
|
if (popup instanceof LightWeightPopup |
588 |
|
|| popup instanceof MediumWeightPopup) |
589 |
|
{ |
590 |
|
JLayeredPane layeredPane; |
591 |
|
layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); |
592 |
|
Point p = new Point(popupLocation.x, popupLocation.y); |
593 |
|
SwingUtilities.convertPointFromScreen(p, layeredPane); |
594 |
|
|
595 |
|
if (size.width + popupLocation.x > screenSize.width) |
596 |
|
popupLocation.x -= size.width; |
597 |
|
if (size.height + popupLocation.y > screenSize.height) |
598 |
|
popupLocation.y -= size.height; |
599 |
|
|
600 |
|
popup.show(p.x, p.y, size.width, size.height); |
601 |
|
} |
602 |
|
else |
603 |
|
{ |
604 |
|
// Subtract insets of the top-level container if popup menu's |
605 |
|
// top-left corner is inside it. |
606 |
|
Insets insets = rootContainer.getInsets(); |
607 |
|
|
608 |
if ((size.width > (rootContainer.getWidth() - popupLocation.x)) |
if (size.width + popupLocation.x > screenSize.width) |
609 |
|| (size.height > (rootContainer.getHeight() - popupLocation.y))) |
popupLocation.x -= size.width; |
610 |
fit = false; |
if (size.height + popupLocation.y > screenSize.height) |
611 |
if (lightWeightPopupEnabled && fit) |
popupLocation.y -= size.height; |
612 |
popup = new LightWeightPopup(this); |
|
613 |
else |
popup.show(popupLocation.x - insets.left, |
614 |
{ |
popupLocation.y - insets.top, |
615 |
if (fit) |
size.width, size.height); |
616 |
popup = new MediumWeightPopup(this); |
} |
617 |
else |
} |
618 |
popup = new HeavyWeightPopup(this); |
else |
619 |
} |
{ |
620 |
if (popup instanceof LightWeightPopup |
firePopupMenuWillBecomeInvisible(); |
621 |
|| popup instanceof MediumWeightPopup) |
popup.hide(); |
622 |
{ |
} |
|
JLayeredPane layeredPane; |
|
|
layeredPane = SwingUtilities.getRootPane(invoker) |
|
|
.getLayeredPane(); |
|
|
Point p = new Point(popupLocation.x, popupLocation.y); |
|
|
SwingUtilities.convertPointFromScreen(p, layeredPane); |
|
|
popup.show(p.x, p.y, size.width, size.height); |
|
|
} |
|
|
else |
|
|
{ |
|
|
// Subtract insets of the top-level container if popup menu's |
|
|
// top-left corner is inside it. |
|
|
Insets insets = rootContainer.getInsets(); |
|
|
popup.show(popupLocation.x - insets.left, |
|
|
popupLocation.y - insets.top, size.width, |
|
|
size.height); |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
firePopupMenuWillBecomeInvisible(); |
|
|
popup.hide(); |
|
|
} |
|
623 |
} |
} |
624 |
} |
} |
625 |
|
|