public int[] getHyperlinkSpan(Document doc, int offset) { JTextComponent target = EditorRegistry.lastFocusedComponent(); final StyledDocument styledDoc = (StyledDocument) target.getDocument(); if (styledDoc == null) { return null; } // Return the position, which was set in the isHyperlink method: return new int[]{startOffset, endOffset}; }
private void insertLinkToEditor() { if (EditorRegistry.lastFocusedComponent() != null) { new InsertLinkAction(EditorRegistry.lastFocusedComponent(), outbox, true, false).actionPerformed(null); } }
private static boolean isCurrentlyOpened(FileObject fo) { JTextComponent component = EditorRegistry.lastFocusedComponent(); if (component == null) { return false; } FileObject opened = NbEditorUtilities.getFileObject(component.getDocument()); if (opened == null) { return false; } return opened.equals(fo); }
public synchronized void initialize() { EditorRegistry.addPropertyChangeListener(this); JTextComponent newComponent = EditorRegistry.lastFocusedComponent(); currentDocument = newComponent != null ? newComponent.getDocument() : null; if (currentDocument != null) { currentDocument.addDocumentListener(this); } }
@Override @CheckForNull public Document getActiveDocument() { final JTextComponent last = EditorRegistry.lastFocusedComponent(); return last == null ? null : last.getDocument(); }
public static JTextComponent findEditor(Document doc) { JTextComponent comp = EditorRegistry.lastFocusedComponent(); if (comp.getDocument() == doc) { return comp; } List<? extends JTextComponent> componentList = EditorRegistry.componentList(); for (JTextComponent component : componentList) { if (comp.getDocument() == doc) { return comp; } } return null; }
/** TODO - MOVE TO UTILITTY LIBRARY */ private static JTextComponent findEditor(Document doc) { JTextComponent comp = EditorRegistry.lastFocusedComponent(); if (comp.getDocument() == doc) { return comp; } List<? extends JTextComponent> componentList = EditorRegistry.componentList(); for (JTextComponent component : componentList) { if (comp.getDocument() == doc) { return comp; } } return null; }
public synchronized void propertyChange(PropertyChangeEvent evt) { assert SwingUtilities.isEventDispatchThread(); JTextComponent newComponent = EditorRegistry.lastFocusedComponent(); Document newDocument = newComponent != null ? newComponent.getDocument() : null; if (currentDocument == newDocument) { return; } if (currentDocument != null) { currentDocument.removeDocumentListener(this); } currentDocument = newDocument; if (currentDocument != null) { currentDocument.addDocumentListener(this); } }
private static void doToggle(final DataObject toggled) { // check if the data object has possibility to be opened in editor final OpenCookie oc = toggled.getLookup().lookup(OpenCookie.class); if (oc != null) { // remember current caret position JTextComponent textComponent = EditorRegistry.lastFocusedComponent(); JumpList.checkAddEntry(textComponent); // try to open ASAP, but better not in EQ RP.post(new Runnable() { @Override public void run() { // open component oc.open(); } }, 0, Thread.MAX_PRIORITY); } }
static CompletionTask createDocTask(ElementHandle element, CompilationInfo info) { // TODO - use ComObjectHandle ?? JavaCompletionQuery query = new JavaCompletionQuery(DOCUMENTATION_QUERY_TYPE, -1); query.element = element; //return new AsyncCompletionTask(query, Registry.getMostActiveComponent()); return new AsyncCompletionTask(query, EditorRegistry.lastFocusedComponent()); }
public static boolean isEnabled() { if (EditorRegistry.lastFocusedComponent() == null || !EditorRegistry.lastFocusedComponent().isShowing()) { return false; } if ( OpenProjects.getDefault().getOpenProjects().length == 0 ){ return false; } final FileObject fileObject = NbEditorUtilities.getFileObject( EditorRegistry.lastFocusedComponent().getDocument()); return isEnabled( fileObject ); /*WebModule webModule = WebModule.getWebModule(fileObject); if ( webModule == null ){ return false; } Profile profile = webModule.getJ2eeProfile(); return Profile.JAVA_EE_6_WEB.equals( profile) || Profile.JAVA_EE_6_FULL.equals( profile );*/ }
@Override public CompletionTask createDocumentationTask() { return new AsyncCompletionTask(new JavaElementDocQuery(elemHandle), EditorRegistry.lastFocusedComponent()); } }
public static void attach(OutputListenerRegistry registry) { JTextComponent pane = EditorRegistry.lastFocusedComponent(); if (pane == null) { return; } Document doc = pane.getDocument(); if (doc == null) { return; } DataObject dobj = (DataObject) doc.getProperty(Document.StreamDescriptionProperty); if (dobj == null) { return; } FileObject file = dobj.getPrimaryFile(); if (file == null) { return; } attachFile(registry, file, doc); }
public static void attach(OutputListenerRegistry registry) { JTextComponent pane = EditorRegistry.lastFocusedComponent(); if (pane == null) { return; } Document doc = pane.getDocument(); if (doc == null) { return; } DataObject dobj = (DataObject) doc.getProperty(Document.StreamDescriptionProperty); if (dobj == null) { return; } FileObject file = dobj.getPrimaryFile(); if (file == null) { return; } attachFile(registry, file, doc); }
@Override public CompletionTask createDocumentationTask() { return new AsyncCompletionTask(new JavaElementDocQuery(elementHandle), EditorRegistry.lastFocusedComponent()); }
public synchronized void stateChanged() { for (JTextComponent c : visibleEditors) { c.removePropertyChangeListener(this); visibleEditors2Files.remove(c); } visibleEditors.clear(); JTextComponent editor = EditorRegistry.lastFocusedComponent(); FileObject fo = editor != null ? getFileObject(editor) : null; if (editor instanceof JEditorPane && fo != null && Source.forFileObject(fo) != null) { visibleEditors.add(editor); } for (JTextComponent c : visibleEditors) { c.addPropertyChangeListener(this); visibleEditors2Files.put(c, getFileObject(c)); } fireChangeEvent(); }
public void start() { // Possibly clear editor from previous error message (#115073) String lastMessage = mostRecentMessage; if (lastMessage != null) { JTextComponent pane = EditorRegistry.lastFocusedComponent(); if (pane != null) { if (pane.isShowing()) { String text = Utilities.getStatusText(pane); if (lastMessage.equals(text)) { Utilities.clearStatusText(pane); } } } mostRecentMessage = null; } resetResults(); }
private TopComponent selectedEditorComponent() { Mode editor = WindowManager.getDefault().findMode("editor");//NOI18N TopComponent tc = editor.getSelectedTopComponent(); TopComponent topComponent = getTopComponent(EditorRegistry.lastFocusedComponent()); if (topComponent == tc) { return tc; } return null; }
public void propertyChange(PropertyChangeEvent evt) { JTextComponent last = EditorRegistry.lastFocusedComponent(); if (last != null){ final NbEditorDocument doc = (NbEditorDocument) last.getDocument(); doc.getDocumentProperties().remove(TextSwitcher.TEXT_SWITCH_SUPPORT); doc.removeDocumentListener(dl); } JTextComponent current = EditorRegistry.focusedComponent(); if (current != null){ final NbEditorDocument doc = (NbEditorDocument) current.getDocument(); doc.addDocumentListener(dl); doc.getDocumentProperties().put(TextSwitcher.TEXT_SWITCH_SUPPORT, new ChangeListener() { public void stateChanged(@SuppressWarnings("unused") //NOI18N final ChangeEvent e) { restartTimer(); } }); restartTimer(); } }
private void insertLink() { Mode editor = WindowManager.getDefault().findMode("editor"); //NOI18N TopComponent tc = editor.getSelectedTopComponent(); if (getTopComponent(EditorRegistry.lastFocusedComponent()) == tc) { insertLinkToEditor(); } else if (tc != null && isIssueRelated(tc)) { insertLinkToIssue(); } else { insertLinkToEditor(); } } private void insertLinkToEditor() {