Changeset 10172 in josm for trunk


Ignore:
Timestamp:
2016-05-10T14:18:05+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #12828 - exception from popup menu (regression from r9916)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r10164 r10172  
    4343import javax.swing.JOptionPane;
    4444import javax.swing.JPanel;
     45import javax.swing.JPopupMenu;
    4546import javax.swing.JScrollPane;
    4647import javax.swing.Scrollable;
     
    478479     */
    479480    public static Window getWindowAncestorFor(EventObject e) {
    480         return e != null && e.getSource() instanceof Component ? SwingUtilities.getWindowAncestor((Component) e.getSource()) : null;
     481        if (e != null) {
     482            Object source = e.getSource();
     483            if (source instanceof Component) {
     484                Window ancestor = SwingUtilities.getWindowAncestor((Component) source);
     485                if (ancestor != null) {
     486                    return ancestor;
     487                } else {
     488                    Container parent = ((Component) source).getParent();
     489                    if (parent instanceof JPopupMenu) {
     490                        Component invoker = ((JPopupMenu) parent).getInvoker();
     491                        return SwingUtilities.getWindowAncestor(invoker);
     492                    }
     493                }
     494            }
     495        }
     496        return null;
    481497    }
    482498
Note: See TracChangeset for help on using the changeset viewer.