This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 216601
Collapse All | Expand All

(-)a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EditorContextDispatcher.java (-9 / +43 lines)
Lines 59-64 Link Here
59
import java.util.Set;
59
import java.util.Set;
60
import java.util.logging.Level;
60
import java.util.logging.Level;
61
import java.util.logging.Logger;
61
import java.util.logging.Logger;
62
import javax.swing.JComponent;
62
import javax.swing.JEditorPane;
63
import javax.swing.JEditorPane;
63
import javax.swing.JRootPane;
64
import javax.swing.JRootPane;
64
import javax.swing.SwingUtilities;
65
import javax.swing.SwingUtilities;
Lines 86-91 Link Here
86
import org.openide.util.RequestProcessor.Task;
87
import org.openide.util.RequestProcessor.Task;
87
import org.openide.util.Utilities;
88
import org.openide.util.Utilities;
88
import org.openide.util.WeakListeners;
89
import org.openide.util.WeakListeners;
90
import org.openide.windows.TopComponent;
89
91
90
/**
92
/**
91
 * Dispatcher of context-related events and provider of active elements in the IDE.
93
 * Dispatcher of context-related events and provider of active elements in the IDE.
Lines 643-656 Link Here
643
                logger.fine("EditorRegistryListener.propertyChange("+propertyName+": "+evt.getOldValue()+" => "+evt.getNewValue()+")");
645
                logger.fine("EditorRegistryListener.propertyChange("+propertyName+": "+evt.getOldValue()+" => "+evt.getNewValue()+")");
644
            }
646
            }
645
            if (propertyName.equals(EditorRegistry.FOCUS_LOST_PROPERTY)) {
647
            if (propertyName.equals(EditorRegistry.FOCUS_LOST_PROPERTY)) {
646
                Object newFocused = evt.getNewValue();
648
                if (ignoreCurrentComponentUpdate((Component) evt.getNewValue())) {
647
                if (newFocused instanceof JRootPane) {
649
                    return ;
648
                    JRootPane root = (JRootPane) newFocused;
649
                    if (root.isAncestorOf((Component) evt.getOldValue())) {
650
                        logger.fine("Focused root.");
651
                        root.addFocusListener(this);
652
                        return;
653
                    }
654
                }
650
                }
655
            }
651
            }
656
            if (propertyName.equals(EditorRegistry.FOCUS_GAINED_PROPERTY) ||
652
            if (propertyName.equals(EditorRegistry.FOCUS_GAINED_PROPERTY) ||
Lines 725-731 Link Here
725
                    return ;
721
                    return ;
726
                }
722
                }
727
            }
723
            }
728
            update(true);
724
            if (!ignoreCurrentComponentUpdate(e.getOppositeComponent())) {
725
                update(true);
726
            }
727
        }
728
        
729
        /**
730
         * Test if the last focused component stays as the current one, or not.
731
         * @param newFocused The newly focused component
732
         * @return if the current component should be updated, or not.
733
         */
734
        private boolean ignoreCurrentComponentUpdate(Component newFocused) {
735
            if (EditorRegistry.focusedComponent() == null) {
736
                JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent();
737
                if (logger.isLoggable(Level.FINE)) {
738
                    logger.fine("lastFocusedComponent = "+lastFocusedComponent);
739
                    logger.fine("newFocused = "+newFocused);
740
                }
741
                if (lastFocusedComponent != null && newFocused != null) {
742
                    // if the last focused component is in the same TopComponent as the newly focused,
743
                    // keep the currentTextComponent as the current one.
744
                    TopComponent activated = TopComponent.getRegistry().getActivated();
745
                    if (logger.isLoggable(Level.FINE)) {
746
                        logger.fine("activated = "+activated);
747
                    }
748
                    if (activated != null) {
749
                        if (logger.isLoggable(Level.FINE)) {
750
                            logger.fine("isAncestorOf = "+(activated.isAncestorOf(lastFocusedComponent) && (newFocused instanceof JRootPane || activated.isAncestorOf(newFocused))));
751
                        }
752
                        if (activated.isAncestorOf(lastFocusedComponent) &&
753
                            (activated.isAncestorOf(newFocused) ||      // either both are in the activated TC,
754
                                newFocused instanceof JRootPane &&      // or JRootPane is the newly focused (menu popup)
755
                                ((JRootPane) newFocused).isAncestorOf(lastFocusedComponent))) {
756
                            newFocused.addFocusListener(this);
757
                            return true;
758
                        }
759
                    }
760
                }
761
            }
762
            return false;
729
        }
763
        }
730
764
731
    }
765
    }

Return to bug 216601