public void eventDispatched(AWTEvent ev) {
int eventID = ev.getID();
if((eventID & AWTEvent.MOUSE_EVENT_MASK) != 0) {
MouseEvent me = (MouseEvent) ev;
if(me.isPopupTrigger()) {
MenuElement[] elems = MenuSelectionManager
.defaultManager()
.getSelectedPath();
if(elems != null && elems.length != 0) {
return;
// We shall not interfere with already opened menu
}
Object c = me.getSource();
JComponent src = null;
if(c instanceof JComponent) {
src = (JComponent) c;
} else if(c instanceof BasicSplitPaneDivider) {
// Special case - if user clicks on divider we must
// invoke popup from the SplitPane
src = (JComponent)
((BasicSplitPaneDivider)c).getParent();
}
if(src != null) {
if(src.getComponentPopupMenu() != null) {
Point pt = src.getPopupLocation(me);
if(pt == null) {
pt = me.getPoint();
pt = SwingUtilities.convertPoint((Component)c,
pt, src);
}
src.getComponentPopupMenu().show(src, pt.x, pt.y);
me.consume();
}
}
}
}
/* Activate a JInternalFrame if necessary. */
if (eventID == MouseEvent.MOUSE_PRESSED) {
Object object = ev.getSource();
if (!(object instanceof Component)) {
return;
}
Component component = (Component)object;
if (component != null) {
Component parent = component;
while (parent != null && !(parent instanceof Window)) {
if (parent instanceof JInternalFrame) {
// Activate the frame.
try { ((JInternalFrame)parent).setSelected(true); }
catch (PropertyVetoException e1) { }
}
parent = parent.getParent();
}
}
}
}
|