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 |
boolean fit = true; |
|
566 |
Dimension size; |
boolean fit = true; |
567 |
|
Dimension size; |
568 |
// Determine the size of the popup menu |
|
569 |
if (this.getSize().width == 0 && this.getSize().width == 0) |
// Determine the size of the popup menu |
570 |
size = this.getPreferredSize(); |
if (this.getSize().width == 0 && this.getSize().width == 0) |
571 |
else |
size = this.getPreferredSize(); |
572 |
size = this.getSize(); |
else |
573 |
|
size = this.getSize(); |
574 |
if ((size.width > (rootContainer.getWidth() - popupLocation.x)) |
|
575 |
|| (size.height > (rootContainer.getHeight() - popupLocation.y))) |
if ((size.width > (rootContainer.getWidth() - popupLocation.x)) |
576 |
fit = false; |
|| (size.height > (rootContainer.getHeight() - popupLocation.y))) |
577 |
if (lightWeightPopupEnabled && fit) |
fit = false; |
578 |
popup = new LightWeightPopup(this); |
if (lightWeightPopupEnabled && fit) |
579 |
else |
popup = new LightWeightPopup(this); |
580 |
{ |
else |
581 |
if (fit) |
{ |
582 |
popup = new MediumWeightPopup(this); |
if (fit) |
583 |
else |
popup = new MediumWeightPopup(this); |
584 |
popup = new HeavyWeightPopup(this); |
else |
585 |
} |
popup = new HeavyWeightPopup(this); |
586 |
if (popup instanceof LightWeightPopup |
} |
587 |
|| popup instanceof MediumWeightPopup) |
if (popup instanceof LightWeightPopup |
588 |
{ |
|| popup instanceof MediumWeightPopup) |
589 |
JLayeredPane layeredPane; |
{ |
590 |
layeredPane = SwingUtilities.getRootPane(invoker) |
JLayeredPane layeredPane; |
591 |
.getLayeredPane(); |
layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); |
592 |
Point p = new Point(popupLocation.x, popupLocation.y); |
Point p = new Point(popupLocation.x, popupLocation.y); |
593 |
SwingUtilities.convertPointFromScreen(p, layeredPane); |
|
594 |
popup.show(p.x, p.y, size.width, size.height); |
if (layeredPane.isShowing()) |
595 |
} |
SwingUtilities.convertPointFromScreen(p, layeredPane); |
596 |
else |
|
597 |
{ |
if (size.width + popupLocation.x > screenSize.width) |
598 |
// Subtract insets of the top-level container if popup menu's |
popupLocation.x -= size.width; |
599 |
// top-left corner is inside it. |
if (size.height + popupLocation.y > screenSize.height) |
600 |
Insets insets = rootContainer.getInsets(); |
popupLocation.y -= size.height; |
601 |
popup.show(popupLocation.x - insets.left, |
|
602 |
popupLocation.y - insets.top, size.width, |
popup.show(p.x, p.y, size.width, size.height); |
603 |
size.height); |
} |
604 |
} |
else |
605 |
} |
{ |
606 |
else |
// Subtract insets of the top-level container if popup menu's |
607 |
{ |
// top-left corner is inside it. |
608 |
firePopupMenuWillBecomeInvisible(); |
Insets insets = rootContainer.getInsets(); |
609 |
popup.hide(); |
|
610 |
} |
if (size.width + popupLocation.x > screenSize.width) |
611 |
|
popupLocation.x -= size.width; |
612 |
|
if (size.height + popupLocation.y > screenSize.height) |
613 |
|
popupLocation.y -= size.height; |
614 |
|
|
615 |
|
popup.show(popupLocation.x - insets.left, |
616 |
|
popupLocation.y - insets.top, |
617 |
|
size.width, size.height); |
618 |
|
} |
619 |
|
} |
620 |
|
else |
621 |
|
{ |
622 |
|
firePopupMenuWillBecomeInvisible(); |
623 |
|
popup.hide(); |
624 |
|
} |
625 |
} |
} |
626 |
} |
} |
627 |
|
|
671 |
*/ |
*/ |
672 |
public void show(Component component, int x, int y) |
public void show(Component component, int x, int y) |
673 |
{ |
{ |
674 |
setInvoker(component); |
if (component.isShowing()) |
675 |
Point p = new Point(x, y); |
{ |
676 |
SwingUtilities.convertPointToScreen(p, component); |
setInvoker(component); |
677 |
setLocation(p.x, p.y); |
Point p = new Point(x, y); |
678 |
setVisible(true); |
SwingUtilities.convertPointToScreen(p, component); |
679 |
|
setLocation(p.x, p.y); |
680 |
|
setVisible(true); |
681 |
|
} |
682 |
} |
} |
683 |
|
|
684 |
/** |
/** |
1021 |
* HeavyWeightPopup is JWindow that is used to display JPopupMenu menu item's |
* HeavyWeightPopup is JWindow that is used to display JPopupMenu menu item's |
1022 |
* on the screen |
* on the screen |
1023 |
*/ |
*/ |
1024 |
private class HeavyWeightPopup extends JWindow implements Popup |
private class HeavyWeightPopup extends JDialog implements Popup |
1025 |
{ |
{ |
1026 |
/** |
/** |
1027 |
* Creates a new HeavyWeightPopup object. |
* Creates a new HeavyWeightPopup object. |
1031 |
public HeavyWeightPopup(Container c) |
public HeavyWeightPopup(Container c) |
1032 |
{ |
{ |
1033 |
this.setContentPane(c); |
this.setContentPane(c); |
1034 |
|
this.setUndecorated(true); |
1035 |
|
this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); |
1036 |
} |
} |
1037 |
|
|
1038 |
/** |
/** |