diff --git a/cnd.completion/src/org/netbeans/modules/cnd/completion/cplusplus/ext/CsmResultItem.java b/cnd.completion/src/org/netbeans/modules/cnd/completion/cplusplus/ext/CsmResultItem.java --- a/cnd.completion/src/org/netbeans/modules/cnd/completion/cplusplus/ext/CsmResultItem.java +++ b/cnd.completion/src/org/netbeans/modules/cnd/completion/cplusplus/ext/CsmResultItem.java @@ -277,10 +277,7 @@ public CompletionTask createDocumentationTask() { CompletionDocumentationProvider p = Lookup.getDefault().lookup(CompletionDocumentationProvider.class); - return p != null ? p.createDocumentationTask(this) : null; -// return new AsyncCompletionTask(new JavaCompletionProvider.DocQuery(this), -// org.netbeans.editor.Registry.getMostActiveComponent()); } public CompletionTask createToolTipTask() { diff --git a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java --- a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java +++ b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java @@ -938,7 +938,6 @@ JavaSource js = JavaSource.forFileObject(fo); if (js == null) return null; final int currentOffset = (ep == null) ? 0 : ep.getCaretPosition(); - //final int currentOffset = org.netbeans.editor.Registry.getMostActiveComponent().getCaretPosition(); final String[] currentMethodPtr = new String[] { null, null, null }; final Future scanFinished; try { @@ -1806,7 +1805,6 @@ currentOffset = 0; } - //final int currentOffset = org.netbeans.editor.Registry.getMostActiveComponent().getCaretPosition(); final String[] currentElementPtr = new String[] { null }; final Future scanFinished; try { diff --git a/editor.lib/apichanges.xml b/editor.lib/apichanges.xml --- a/editor.lib/apichanges.xml +++ b/editor.lib/apichanges.xml @@ -104,6 +104,23 @@ + + Cleaning up o.n.editor.Registry + + + + + +

+ o.n.editor.Registry was internally bridged to o.n.api.editor.EditorRegistry + and some of its methods were removed from API. @PatchedPublic was used to preserve binary compatibility. + The whole class has been deprecated for a long time + and its usage is discouraged in favor of EditorRegistry. +

+
+ +
+ Removing DrawLayer and related API diff --git a/editor.lib/nbproject/project.properties b/editor.lib/nbproject/project.properties --- a/editor.lib/nbproject/project.properties +++ b/editor.lib/nbproject/project.properties @@ -39,7 +39,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.5 -spec.version.base=2.1.0 +spec.version.base=2.2 is.autoload=true javadoc.arch=${basedir}/arch.xml diff --git a/editor.lib/src/org/netbeans/editor/BaseDocument.java b/editor.lib/src/org/netbeans/editor/BaseDocument.java --- a/editor.lib/src/org/netbeans/editor/BaseDocument.java +++ b/editor.lib/src/org/netbeans/editor/BaseDocument.java @@ -528,11 +528,6 @@ ((BaseKit) kit).initDocument(this); } - // Possibly add the document to registry - if (addToRegistry) { - Registry.addDocument(this); // add if created thru the kit - } - // Start listen on find-support findSupportListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { diff --git a/editor.lib/src/org/netbeans/editor/BaseTextUI.java b/editor.lib/src/org/netbeans/editor/BaseTextUI.java --- a/editor.lib/src/org/netbeans/editor/BaseTextUI.java +++ b/editor.lib/src/org/netbeans/editor/BaseTextUI.java @@ -251,8 +251,6 @@ SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, null); - Registry.addComponent(component); - Registry.activate(component); EditorApiPackageAccessor.get().register(component); component.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); } @@ -281,7 +279,6 @@ comp.setCaret(null); getEditorUI().uninstallUI(comp); - Registry.removeComponent(comp); } } @@ -412,7 +409,6 @@ if (newDoc != null) { newDoc.addDocumentListener(this); - Registry.activate(newDoc); // Activate the new document } } else if ("ancestor".equals(propName)) { // NOI18N JTextComponent comp = (JTextComponent)evt.getSource(); diff --git a/editor.lib/src/org/netbeans/editor/EditorUI.java b/editor.lib/src/org/netbeans/editor/EditorUI.java --- a/editor.lib/src/org/netbeans/editor/EditorUI.java +++ b/editor.lib/src/org/netbeans/editor/EditorUI.java @@ -279,7 +279,6 @@ public EditorUI() { focusL = new FocusAdapter() { public @Override void focusGained(FocusEvent evt) { - Registry.activate(getComponent()); /* Fix of #25475 - copyAction's enabled flag * must be updated on focus change */ diff --git a/editor.lib/src/org/netbeans/editor/JumpList.java b/editor.lib/src/org/netbeans/editor/JumpList.java --- a/editor.lib/src/org/netbeans/editor/JumpList.java +++ b/editor.lib/src/org/netbeans/editor/JumpList.java @@ -266,7 +266,6 @@ if (Utilities.getLastActiveComponent() != c) { Utilities.requestFocus(c); // possibly request for the component - Registry.activate(c); } int offset = wpt.getOffset(); diff --git a/editor.lib/src/org/netbeans/editor/Registry.java b/editor.lib/src/org/netbeans/editor/Registry.java --- a/editor.lib/src/org/netbeans/editor/Registry.java +++ b/editor.lib/src/org/netbeans/editor/Registry.java @@ -41,12 +41,17 @@ package org.netbeans.editor; -import java.lang.ref.WeakReference; -import java.util.ArrayList; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; import java.util.Iterator; +import java.util.List; import javax.swing.text.JTextComponent; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; +import javax.swing.text.Document; +import org.netbeans.api.editor.EditorRegistry; +import org.openide.modules.PatchedPublic; /** * All the documents and components register here so that @@ -61,32 +66,12 @@ */ public class Registry { - private static final WeakReference[] EMPTY = new WeakReference[0]; - - /** Array of weak references to documents */ - private static WeakReference[] docRefs = EMPTY; - - /** Number of the document references */ - private static int docRefsCount; - - /** Array of activated document numbers */ - private static final ArrayList docAct = new ArrayList(); - - /** Array list of weak references to components */ - private static WeakReference[] compRefs = EMPTY; - - /** Number of the document references */ - private static int compRefsCount; - - /** Array of activated component numbers */ - private static final ArrayList compAct = new ArrayList(); - /** List of the registered changes listeners */ private static final WeakEventListenerList listenerList = new WeakEventListenerList(); + + private static PropertyChangeListener editorRegistryListener = null; - private static int consolidateCounter; - /** Add weak listener to listen to change of activity of documents or components. * The caller must * hold the listener object in some instance variable to prevent it @@ -94,6 +79,7 @@ * @param l listener to add */ public static void addChangeListener(ChangeListener l) { + registerListener(); listenerList.add(ChangeListener.class, l); } @@ -103,6 +89,7 @@ * @param l listener to remove */ public static void removeChangeListener(ChangeListener l) { + registerListener(); listenerList.remove(ChangeListener.class, l); } @@ -110,17 +97,20 @@ * @return document id or -1 if document was not yet added to the registry * by addDocument(). */ - public static synchronized int getID(BaseDocument doc) { - Integer i = getIDInteger(doc); - return (i != null) ? i.intValue() : -1; + @PatchedPublic + private static int getID(BaseDocument doc) { + registerListener(); + return -1; } /** Get component ID from the component. * @return component id or -1 if component was not yet added to the registry * by addComponent(). */ - public static synchronized int getID(JTextComponent c) { - return getIDImpl(c); + @PatchedPublic + private static int getID(JTextComponent c) { + registerListener(); + return -1; } /** Get document when its ID is known. @@ -129,13 +119,10 @@ * by getID(doc). * @return document instance or null when document no longer exists */ - public static synchronized BaseDocument getDocument(int docID) { - if (docID < 0 || docID >= docRefsCount) { - return null; - } - - WeakReference wr = docRefs[docID]; - return (wr != null) ? (BaseDocument)wr.get() : null; + @PatchedPublic + private static BaseDocument getDocument(int docID) { + registerListener(); + return null; } /** Get component when its ID is known. @@ -144,32 +131,20 @@ * by getID(c). * @return component instance or null when document no longer exists */ - public static synchronized JTextComponent getComponent(int compID) { - if (compID < 0 || compID >= compRefsCount) { - return null; - } - - WeakReference wr = compRefs[compID]; - return (wr != null) ? (JTextComponent)wr.get() : null; + @PatchedPublic + private static JTextComponent getComponent(int compID) { + registerListener(); + return null; } /** Add document to registry. Doesn't search for repetitive * adding. * @return registry unique ID of the document */ - public static synchronized int addDocument(BaseDocument doc) { - Integer docID = getIDInteger(doc); - if (docID != null) { // already added - return docID.intValue(); - } - - if (docRefsCount >= docRefs.length) { - docRefs = realloc(docRefs); - } - - docRefs[docRefsCount] = new WeakReference(doc); - doc.putProperty(BaseDocument.ID_PROP, new Integer(docRefsCount)); - return docRefsCount++; + @PatchedPublic + private static int addDocument(BaseDocument doc) { + registerListener(); + return -1; } /** Add component to registry. If the component is already registered @@ -177,22 +152,10 @@ * to the component is _not_ registered automatically. * @return ID of the component */ - public static synchronized int addComponent(JTextComponent c) { - int compID = getIDImpl(c); - if (compID != -1) { - if (compRefs[compID] == null) { // unregistered previously by removeComponent() - compRefs[compID] = new WeakReference(c); - } - return compID; // already registered - } - - if (compRefsCount >= compRefs.length) { - compRefs = realloc(compRefs); - } - - compRefs[compRefsCount] = new WeakReference(c); - ((BaseTextUI)c.getUI()).componentID = compRefsCount; - return compRefsCount++; + @PatchedPublic + private static int addComponent(JTextComponent c) { + registerListener(); + return -1; } /** Remove component from registry. It's usually done when @@ -201,78 +164,18 @@ * new ID will be different from this one. -1 will be returned * if the component was not yet added to the registry. */ - public static int removeComponent(JTextComponent c) { - int compID; - boolean lastComponent = false; - - synchronized (Registry.class) { - compID = getIDImpl(c); - - if (compID != -1) { - compRefs[compID] = null; - // Search whether was activated - for (int i = compAct.size() - 1; i >= 0; i--) { - if (compAct.get(i) == compID) { - compAct.remove(i); - break; - } - } - - lastComponent = compAct.isEmpty(); - } - } - - if (lastComponent) { - fireChange(); - } - - return compID; + @PatchedPublic + private static int removeComponent(JTextComponent c) { + registerListener(); + return -1; } /** Put the component to the first position in the array of last accessed * components. The activate of document is also called automatically. */ - public static void activate(JTextComponent c) { - boolean activated = true; - synchronized (Registry.class) { - int compID = getIDImpl(c); - if (compID == -1) { // c not registered - return; - } - - int actSize = compAct.size(); - int ind = 0; - while (ind < actSize) { - int id = compAct.get(ind); - if (id == compID) { // found - if (ind == 0) { - break; - } - compAct.add(0, compAct.remove(ind)); - activated = true; - break; - } - - ind++; - } - - if (ind == actSize) { - compAct.add(0, compID); - activated = true; - } - - // Try to activate component's document too - Object doc = c.getDocument(); - if (doc instanceof BaseDocument) { - if (doActivate((BaseDocument)doc)) { - activated = true; - } - } - } - - if (activated) { - fireChange(); - } + @PatchedPublic + private static void activate(JTextComponent c) { + registerListener(); } /** Put the document to the first position in the array of last accessed @@ -280,40 +183,45 @@ * is done. * @param doc document to be activated */ - public static void activate(BaseDocument doc) { - boolean activated; - synchronized (Registry.class) { - activated = doActivate(doc); - } - - if (activated) { - fireChange(); - } + @PatchedPublic + private static void activate(BaseDocument doc) { + registerListener(); } - public static synchronized BaseDocument getMostActiveDocument() { - return getValidDoc(0, true); + public static BaseDocument getMostActiveDocument() { + registerListener(); + JTextComponent jtc = getMostActiveComponent(); + return jtc == null ? null : Utilities.getDocument(jtc); } - public static synchronized BaseDocument getLeastActiveDocument() { - int lastInd = docAct.size() - 1; - return getValidDoc(lastInd, false); + public static BaseDocument getLeastActiveDocument() { + registerListener(); + JTextComponent jtc = getLeastActiveComponent(); + return jtc == null ? null : Utilities.getDocument(jtc); } - public static BaseDocument getLessActiveDocument(BaseDocument doc) { - return getLessActiveDocument(getID(doc)); + @PatchedPublic + private static BaseDocument getLessActiveDocument(BaseDocument doc) { + registerListener(); + return null; } - public static synchronized BaseDocument getLessActiveDocument(int docID) { - return getNextActiveDoc(docID, true); + @PatchedPublic + private static BaseDocument getLessActiveDocument(int docID) { + registerListener(); + return null; } - public static BaseDocument getMoreActiveDocument(BaseDocument doc) { - return getMoreActiveDocument(getID(doc)); + @PatchedPublic + private static BaseDocument getMoreActiveDocument(BaseDocument doc) { + registerListener(); + return null; } - public static synchronized BaseDocument getMoreActiveDocument(int docID) { - return getNextActiveDoc(docID, false); + @PatchedPublic + private static BaseDocument getMoreActiveDocument(int docID) { + registerListener(); + return null; } /** Get the iterator over the active documents. It starts with @@ -321,207 +229,76 @@ * It's just the current snapshot so the iterator will * not reflect future changes. */ - public static synchronized Iterator getDocumentIterator() { - consolidate(); + public static Iterator getDocumentIterator() { + registerListener(); + final Iterator cIt = getComponentIterator(); + return new Iterator() { + public boolean hasNext() { + return cIt.hasNext(); + } - ArrayList docList = new ArrayList(); - int actSize = docAct.size(); - for (int i = 0; i < actSize; i++) { - int ind = ((Integer)docAct.get(i)).intValue(); - WeakReference wr = docRefs[ind]; - if (wr != null) { - Object doc = wr.get(); - if (doc != null) { - docList.add(doc); - } + public Document next() { + return cIt.next().getDocument(); } - } - return docList.iterator(); + public void remove() { + cIt.remove(); + } + }; } - public static synchronized JTextComponent getMostActiveComponent() { - return getValidComp(0, true); + public static JTextComponent getMostActiveComponent() { + registerListener(); + return EditorRegistry.focusedComponent(); } - public static synchronized JTextComponent getLeastActiveComponent() { - int lastInd = compAct.size() - 1; - return getValidComp(lastInd, false); + public static JTextComponent getLeastActiveComponent() { + registerListener(); + List l = EditorRegistry.componentList(); + return l.size() > 0 ? l.get(l.size() - 1) : null; } - public static JTextComponent getLessActiveComponent(JTextComponent c) { - return getLessActiveComponent(getID(c)); + @PatchedPublic + private static JTextComponent getLessActiveComponent(JTextComponent c) { + registerListener(); + return null; } - public static synchronized JTextComponent getLessActiveComponent(int compID) { - return getNextActiveComp(compID, true); + @PatchedPublic + private static JTextComponent getLessActiveComponent(int compID) { + registerListener(); + return null; } - public static JTextComponent getMoreActiveComponent(JTextComponent c) { - return getMoreActiveComponent(getID(c)); + @PatchedPublic + private static JTextComponent getMoreActiveComponent(JTextComponent c) { + registerListener(); + return null; } - public static synchronized JTextComponent getMoreActiveComponent(int compID) { - return getNextActiveComp(compID, false); + @PatchedPublic + private static JTextComponent getMoreActiveComponent(int compID) { + registerListener(); + return null; } /** Get the iterator over the active components. It starts with * the most active component till the least active component. */ - public static synchronized Iterator getComponentIterator() { - consolidate(); - - ArrayList compList = new ArrayList(); - int actSize = compAct.size(); - for (int i = 0; i < actSize; i++) { - int ind = compAct.get(i); - WeakReference wr = compRefs[ind]; - if (wr != null) { - Object comp = wr.get(); - if (comp != null) { - compList.add(comp); - } - } - } - - return compList.iterator(); + public static Iterator getComponentIterator() { + registerListener(); + return EditorRegistry.componentList().iterator(); } - private static WeakReference[] realloc(WeakReference[] refs) { - WeakReference[] tmp = new WeakReference[refs.length * 2 + 4]; - System.arraycopy(refs, 0, tmp, 0, refs.length); - return tmp; - } - - private static void consolidate() { - while (++consolidateCounter >= 20) { // after every 20th call - consolidateCounter = 0; - - // Remove empty document references - for (int i = docAct.size() - 1; i >= 0; i--) { - int ind = ((Integer)docAct.get(i)).intValue(); - WeakReference wr = docRefs[ind]; - if (wr != null) { - if (wr.get() == null) { // empty reference - docAct.remove(i); - docRefs[ind] = null; - } - } - } - - // Remove empty component references - for (int i = compAct.size() - 1; i >= 0; i--) { - int ind = compAct.get(i); - WeakReference wr = compRefs[ind]; - if (wr != null) { - if (wr.get() == null) { // empty reference - compAct.remove(i); - compRefs[ind] = null; - } - } - } - } - } - - private static int getIDImpl(JTextComponent c) { - if (c == null) { - return -1; + private static synchronized void registerListener() { + if (editorRegistryListener == null) { + editorRegistryListener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + fireChange(); + } + }; + EditorRegistry.addPropertyChangeListener(editorRegistryListener); } - return ((BaseTextUI)c.getUI()).componentID; - } - - private static Integer getIDInteger(BaseDocument doc) { - if (doc == null) { - return null; - } - - return (Integer)doc.getProperty(BaseDocument.ID_PROP); - } - - private static boolean doActivate(BaseDocument doc) { - Integer docIDInteger = getIDInteger(doc); - - if (docIDInteger == null) { - return false; // document not added to registry - } - - int docID = (docIDInteger != null) ? docIDInteger.intValue() : -1; - - int size = docAct.size(); - for (int ind = 0; ind < size; ind++) { - int id = ((Integer)docAct.get(ind)).intValue(); - if (id == docID) { - if (ind == 0) { // no change - return false; - } - - docAct.add(0, docAct.remove(ind)); - return true; - } - } - - docAct.add(0, docIDInteger); - return true; - } - - private static BaseDocument getValidDoc(int ind, boolean forward) { - consolidate(); - - int actSize = docAct.size(); - while (ind >= 0 && ind < actSize) { - int docID = ((Integer)docAct.get(ind)).intValue(); - WeakReference wr = docRefs[docID]; - BaseDocument doc = (wr != null) ? (BaseDocument)wr.get() : null; - if (doc != null) { - return doc; - } - ind += forward ? +1 : -1; - } - return null; - } - - private static BaseDocument getNextActiveDoc(int docID, boolean forward) { - consolidate(); - - int actSize = docAct.size(); - int ind = forward ? 0 : (actSize - 1); - while (ind >= 0 && ind < actSize) { - if (((Integer)docAct.get(ind)).intValue() == docID) { - ind += forward ? +1 : -1; // get next one - return getValidDoc(ind, forward); - } - ind += forward ? +1 : -1; - } - return null; - } - - private static JTextComponent getValidComp(int ind, boolean forward) { - consolidate(); - - int actSize = compAct.size(); - while (ind >= 0 && ind < actSize) { - int compID = compAct.get(ind); - WeakReference wr = compRefs[compID]; - JTextComponent c = (wr != null) ? (JTextComponent)wr.get() : null; - if (c != null) { - return c; - } - ind += forward ? +1 : -1; - } - return null; - } - - private static JTextComponent getNextActiveComp(int compID, boolean forward) { - int actSize = compAct.size(); - int ind = forward ? 0 : (actSize - 1); - while (ind >= 0 && ind < actSize) { - if (compAct.get(ind) == compID) { - ind += forward ? +1 : -1; - return getValidComp(ind, forward); - } - ind += forward ? +1 : -1; - } - return null; } private static void fireChange() { @@ -534,34 +311,15 @@ } /** Debug the registry into string. */ - public static synchronized String registryToString() { - StringBuffer sb = new StringBuffer(); - sb.append("Document References:\n"); // NOI18N - for (int i = 0; i < docRefsCount; i++) { - WeakReference wr = docRefs[i]; - sb.append("docRefs[" + i + "]=" + ((wr != null) ? wr.get() : "null") + "\n"); // NOI18N + public static String registryToString() { + registerListener(); + try { + Method m = EditorRegistry.class.getDeclaredMethod("dumpItemList"); //NOI18N + return (String) m.invoke(null); + } catch (Exception e) { + // ignore; + return ""; //NOI18N } - sb.append("Component References:\n"); // NOI18N - for (int i = 0; i < compRefsCount; i++) { - WeakReference wr = (WeakReference)compRefs[i]; - sb.append("compRefs[" + i + "]=" + ((wr != null) ? wr.get() : "null") + "\n"); // NOI18N - } - sb.append("\nActive Document Indexes:\n"); // NOI18N - for (int i = 0; i < docAct.size(); i++) { - sb.append(docAct.get(i)); - if (i != docAct.size() - 1) { - sb.append(", "); // NOI18N - } - } - sb.append("\nActive Component Indexes:\n"); // NOI18N - for (int i = 0; i < compAct.size(); i++) { - sb.append(compAct.get(i)); - if (i != compAct.size() - 1) { - sb.append(", "); // NOI18N - } - } - - return sb.toString(); } } diff --git a/editor.lib/src/org/netbeans/editor/WordMatch.java b/editor.lib/src/org/netbeans/editor/WordMatch.java --- a/editor.lib/src/org/netbeans/editor/WordMatch.java +++ b/editor.lib/src/org/netbeans/editor/WordMatch.java @@ -45,12 +45,14 @@ import java.beans.PropertyChangeListener; import java.util.HashMap; import java.util.ArrayList; +import java.util.List; import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; import javax.swing.text.Position; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.EditorRegistry; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults; import org.netbeans.modules.editor.lib2.EditorPreferencesKeys; @@ -450,7 +452,16 @@ if (doc == getStaticWordsDoc()) { return null; } - BaseDocument nextDoc = Registry.getLessActiveDocument(doc); + BaseDocument nextDoc = null; + List list = EditorRegistry.componentList(); + for(int i = 0; i < list.size(); i++) { + if (doc == list.get(i).getDocument()) { + if (i + 1 < list.size()) { + nextDoc = Utilities.getDocument(list.get(i + 1)); + } + break; + } + } if (nextDoc == null) { nextDoc = getStaticWordsDoc(); } @@ -527,7 +538,7 @@ public @Override String toString() { return "{word='" + word + "', pos=" + pos.getOffset() // NOI18N - + ", doc=" + Registry.getID(doc) + "}"; // NOI18N + + ", doc=" + doc + "}"; // NOI18N } } // End of WordInfo class diff --git a/editor/src/org/netbeans/modules/editor/MainMenuAction.java b/editor/src/org/netbeans/modules/editor/MainMenuAction.java --- a/editor/src/org/netbeans/modules/editor/MainMenuAction.java +++ b/editor/src/org/netbeans/modules/editor/MainMenuAction.java @@ -41,6 +41,8 @@ package org.netbeans.modules.editor; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.prefs.Preferences; import javax.swing.Action; @@ -60,7 +62,6 @@ import org.netbeans.api.editor.settings.KeyBindingSettings; import org.netbeans.api.editor.settings.SimpleValueNames; import org.netbeans.editor.BaseKit; -import org.netbeans.editor.Registry; import org.netbeans.editor.Utilities; import org.netbeans.editor.ext.ExtKit; import org.netbeans.lib.editor.util.swing.DocumentUtilities; @@ -197,7 +198,11 @@ if (kbs == null) { // needs to listen on Registry - resultChanged event is fired before // TopComponent is really focused - this causes problems in getComponent method - Registry.addChangeListener(this); + EditorRegistry.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + setMenu(); + } + }); kbs = MimeLookup.getLookup(MimePath.EMPTY).lookupResult(KeyBindingSettings.class); kbs.addLookupListener(WeakListeners.create(LookupListener.class, this, kbs)); kbs.allInstances(); diff --git a/java.editor/src/org/netbeans/modules/java/editor/semantic/OccurrencesMarkProviderCreator.java b/java.editor/src/org/netbeans/modules/java/editor/semantic/OccurrencesMarkProviderCreator.java --- a/java.editor/src/org/netbeans/modules/java/editor/semantic/OccurrencesMarkProviderCreator.java +++ b/java.editor/src/org/netbeans/modules/java/editor/semantic/OccurrencesMarkProviderCreator.java @@ -40,9 +40,7 @@ */ package org.netbeans.modules.java.editor.semantic; -import javax.swing.text.Document; import javax.swing.text.JTextComponent; -import org.netbeans.editor.Registry; import org.netbeans.modules.editor.errorstripe.privatespi.MarkProvider; import org.netbeans.modules.editor.errorstripe.privatespi.MarkProviderCreator; diff --git a/jellytools.ide/src/org/netbeans/jellytools/modules/editor/CompletionJListOperator.java b/jellytools.ide/src/org/netbeans/jellytools/modules/editor/CompletionJListOperator.java --- a/jellytools.ide/src/org/netbeans/jellytools/modules/editor/CompletionJListOperator.java +++ b/jellytools.ide/src/org/netbeans/jellytools/modules/editor/CompletionJListOperator.java @@ -48,28 +48,24 @@ import java.util.List; import java.util.logging.Logger; import javax.swing.JList; -import javax.swing.JScrollPane; -import javax.swing.ListModel; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.EditorRegistry; import org.netbeans.api.editor.completion.Completion; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Registry; +import org.netbeans.editor.Utilities; import org.netbeans.jellytools.Bundle; -import org.netbeans.jemmy.ComponentSearcher; import org.netbeans.jemmy.JemmyException; import org.netbeans.jemmy.QueueTool; -import org.netbeans.jemmy.TimeoutExpiredException; import org.netbeans.jemmy.Timeouts; import org.netbeans.jemmy.Waitable; import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.operators.JListOperator; -import org.netbeans.jemmy.operators.JScrollPaneOperator; import org.netbeans.modules.editor.completion.CompletionImpl; import org.netbeans.modules.editor.completion.CompletionJList; import org.netbeans.jemmy.operators.Operator; -import org.netbeans.jemmy.util.EmptyVisualizer; /** @@ -312,8 +308,11 @@ }; public static void start() { - doc = Registry.getMostActiveDocument(); - doc.addDocumentListener(listener); + JTextComponent jtc = EditorRegistry.focusedComponent(); + doc = jtc != null ? Utilities.getDocument(jtc) : null; + if (doc != null) { + doc.addDocumentListener(listener); + } modified = false; active = true; } diff --git a/profiler.projectsupport/nbproject/project.xml b/profiler.projectsupport/nbproject/project.xml --- a/profiler.projectsupport/nbproject/project.xml +++ b/profiler.projectsupport/nbproject/project.xml @@ -59,6 +59,15 @@ + org.netbeans.modules.editor.lib2 + + + + 1 + 1.0 + + + org.netbeans.modules.java.platform diff --git a/profiler.projectsupport/src/org/netbeans/modules/profiler/projectsupport/utilities/SourceUtils.java b/profiler.projectsupport/src/org/netbeans/modules/profiler/projectsupport/utilities/SourceUtils.java --- a/profiler.projectsupport/src/org/netbeans/modules/profiler/projectsupport/utilities/SourceUtils.java +++ b/profiler.projectsupport/src/org/netbeans/modules/profiler/projectsupport/utilities/SourceUtils.java @@ -76,7 +76,6 @@ import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import java.io.IOException; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -110,10 +109,8 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import javax.swing.JEditorPane; -import javax.swing.SwingUtilities; import javax.swing.text.JTextComponent; -import org.netbeans.api.java.source.ui.ElementOpen; -import org.netbeans.lib.profiler.common.Profiler; +import org.netbeans.api.editor.EditorRegistry; import org.netbeans.modules.profiler.utilities.OutputParameter; /** @@ -328,7 +325,7 @@ * @return The caret offset or -1 */ public static int getCurrentOffsetInEditor() { - JTextComponent mostActiveEditor = org.netbeans.editor.Registry.getMostActiveComponent(); + JTextComponent mostActiveEditor = EditorRegistry.focusedComponent(); if ((mostActiveEditor != null) && (mostActiveEditor.getCaret() != null)) { return mostActiveEditor.getCaretPosition(); diff --git a/profiler/nbproject/project.xml b/profiler/nbproject/project.xml --- a/profiler/nbproject/project.xml +++ b/profiler/nbproject/project.xml @@ -145,6 +145,15 @@ + org.netbeans.modules.editor.lib2 + + + + 1 + 1.0 + + + org.netbeans.modules.editor.mimelookup diff --git a/profiler/src/org/netbeans/modules/profiler/ppoints/Utils.java b/profiler/src/org/netbeans/modules/profiler/ppoints/Utils.java --- a/profiler/src/org/netbeans/modules/profiler/ppoints/Utils.java +++ b/profiler/src/org/netbeans/modules/profiler/ppoints/Utils.java @@ -45,7 +45,6 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.ProjectUtils; -import org.netbeans.editor.Registry; import org.netbeans.lib.profiler.common.Profiler; import org.netbeans.lib.profiler.global.ProfilingSessionStatus; import org.netbeans.lib.profiler.ui.components.table.EnhancedTableCellRenderer; @@ -87,6 +86,7 @@ import javax.swing.text.Document; import javax.swing.text.JTextComponent; import javax.swing.text.StyledDocument; +import org.netbeans.api.editor.EditorRegistry; import org.netbeans.modules.profiler.NetBeansProfiler; import org.netbeans.modules.profiler.projectsupport.utilities.ProjectUtilities; import org.netbeans.modules.profiler.projectsupport.utilities.SourceUtils; @@ -891,10 +891,7 @@ } private static JavaEditorContext getMostActiveJavaEditorContext() { - Iterator componentIterator = Registry.getComponentIterator(); - - while (componentIterator.hasNext()) { - JTextComponent component = (JTextComponent) componentIterator.next(); + for (JTextComponent component : EditorRegistry.componentList()) { Document document = component.getDocument(); FileObject fileObject = NbEditorUtilities.getFileObject(document); diff --git a/profiler/src/org/netbeans/modules/profiler/ppoints/ui/ToggleProfilingPointAction.java b/profiler/src/org/netbeans/modules/profiler/ppoints/ui/ToggleProfilingPointAction.java --- a/profiler/src/org/netbeans/modules/profiler/ppoints/ui/ToggleProfilingPointAction.java +++ b/profiler/src/org/netbeans/modules/profiler/ppoints/ui/ToggleProfilingPointAction.java @@ -41,7 +41,6 @@ package org.netbeans.modules.profiler.ppoints.ui; import org.netbeans.api.project.Project; -import org.netbeans.editor.Registry; import org.netbeans.lib.profiler.ui.components.ThinBevelBorder; import org.netbeans.modules.editor.NbEditorUtilities; import org.netbeans.modules.profiler.NetBeansProfiler; @@ -85,6 +84,7 @@ import javax.swing.border.Border; import javax.swing.text.Document; import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.EditorRegistry; import org.openide.util.Utilities; @@ -338,7 +338,7 @@ } // Get most active editor - JTextComponent editor = Registry.getMostActiveComponent(); + JTextComponent editor = EditorRegistry.focusedComponent(); if (editor == null) { return false; diff --git a/python.debugger/src/org/netbeans/modules/python/debugger/config/NetBeansFrontend.java b/python.debugger/src/org/netbeans/modules/python/debugger/config/NetBeansFrontend.java --- a/python.debugger/src/org/netbeans/modules/python/debugger/config/NetBeansFrontend.java +++ b/python.debugger/src/org/netbeans/modules/python/debugger/config/NetBeansFrontend.java @@ -38,8 +38,6 @@ */ package org.netbeans.modules.python.debugger.config; -import org.netbeans.editor.Registry; - import org.openide.ErrorManager; import org.openide.filesystems.*; @@ -48,6 +46,8 @@ import java.io.*; import javax.swing.JOptionPane; import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.EditorRegistry; import org.netbeans.modules.python.debugger.PythonDebugException; import org.netbeans.modules.python.debugger.PythonDebugParameters; import org.netbeans.modules.python.debugger.Utils; @@ -284,10 +284,14 @@ * send back the current selected focussed source full path info */ public String getCurrentSource() { - Document doc = Registry.getMostActiveDocument(); - - System.out.println("NB currentSource =" + Utils.getDocumentSource(doc)); - return Utils.getDocumentSource(doc); + JTextComponent jtc = EditorRegistry.focusedComponent(); + if (jtc != null) { + Document doc = jtc.getDocument(); + System.out.println("NB currentSource =" + Utils.getDocumentSource(doc)); + return Utils.getDocumentSource(doc); + } else { + return null; + } } /**