protected void dispatchEvent(AWTEvent event) {
// stop auto scrolling on any mouse event
try {
if (event instanceof MouseEvent) {
MouseEvent me = (MouseEvent) event;
if (me.getButton() != MouseEvent.NOBUTTON && me.getID() == MouseEvent.MOUSE_CLICKED) {
if (MainFrame.getInstance().getProgramTableScrollPane().getProgramTable().stopAutoScroll()) {
return;
}
}
}
} catch (Exception e1) {
// TODO Auto-generated catch block
// e1.printStackTrace();
}
try {
super.dispatchEvent(event);
}catch(Throwable e) {
// e.printStackTrace();
return;}
// interested only in mouseevents
if (!(event instanceof MouseEvent)) {
return;
}
MouseEvent me = (MouseEvent) event;
// interested only in popuptriggers
if (!me.isPopupTrigger() || me.getComponent() == null) {
return;
}
// me.getComponent(...) returns the heavy weight component on which event
// occured
Component comp = SwingUtilities.getDeepestComponentAt(me.getComponent(), me.getX(), me.getY());
// interested only in textcomponents
if (!(comp instanceof JTextComponent)) {
return;
}
// no popup shown by user code
if (MenuSelectionManager.defaultManager().getSelectedPath().length > 0) {
return;
}
// create popup menu and show
JTextComponent tc = (JTextComponent) comp;
JPopupMenu menu = new JPopupMenu();
addStandardContextMenu(tc, menu);
Point pt = SwingUtilities
.convertPoint(me.getComponent(), me.getPoint(), tc);
menu.show(tc, pt.x, pt.y);
}