int offset = nextSearchOffset; boolean searching = true; CharSequence content = DocumentUtilities.getText(doc); if (!Character.isLetter(c)) { nextSearchOffset = offset; currentWord = doc.getText(currentStartOffset, offset - currentStartOffset); return true; nextSearchOffset = doc.getLength(); currentWord = doc.getText(currentStartOffset, doc.getLength() - currentStartOffset);
/** * Returns true if bracket completion is enabled in options. */ static boolean completionSettingEnabled(Document doc) { Preferences prefs = MimeLookup.getLookup(DocumentUtilities.getMimeType(doc)).lookup(Preferences.class); return prefs.getBoolean(SimpleValueNames.COMPLETION_PAIR_CHARACTERS, true); }
@Override public void run() { try { version = org.netbeans.lib.editor.util.swing.DocumentUtilities.getDocumentTimestamp(doc); final int length = doc.getLength(); char[] buf = new char[length]; DocumentUtilities.copyText(doc, 0, length, buf, 0); res[0] = buf; } catch( BadLocationException e ) { res[1] = e; } } });
component.putClientProperty(PROP_SIDEBAR_MARK, this); } else { if (LOG.isLoggable(Level.FINE)) { doc.addDocumentListener(WeakListeners.document(listener, doc)); setOpaque(true); prefs = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component)).lookup(Preferences.class); prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefsListener, prefs)); prefsListener.preferenceChange(null);
try { doc.insertString(c.getCaretPosition(), paramName, null); substed = true; } catch (BadLocationException e) { boolean addSpace = CodeStyle.getDefault(doc).spaceAfterComma(); try { if (addSpace && (ind == 0 || (offset > 0 && Character.isWhitespace(DocumentUtilities.getText(doc, offset - 1, 1).charAt(0))))) { addSpace = false; Preferences prefs = MimeLookup.getLookup(mimeType).lookup(Preferences.class); addClosingParen = prefs.getBoolean(SimpleValueNames.COMPLETION_PAIR_CHARACTERS, false); String paramsText = null; try { int fnwpos = Utilities.getFirstNonWhiteFwd(doc, offset + len); if (fnwpos > -1 && fnwpos <= Utilities.getRowEnd(doc, offset + len) && doc.getChars(fnwpos, 1)[0] == '(') { // NOI18N CharSequence textToReplace = DocumentUtilities.getText(doc, offset, len); if (CharSequenceUtilities.textEquals(text, textToReplace)) { c.setCaretPosition(offset + len); res[0] = false; c.setCaretPosition(insertOffset + insertText.length());
public FoldViewFactory(View documentView) { super(documentView); foldHierarchy = FoldHierarchy.get(textComponent()); foldHierarchy.addFoldHierarchyListener(this); viewFoldsExpanded = Boolean.TRUE.equals(textComponent().getClientProperty(VIEW_FOLDS_EXPANDED_PROPERTY)); String mime = DocumentUtilities.getMimeType(document()); Lookup lkp = MimeLookup.getLookup(mime); colorSource = lkp.lookupResult(FontColorSettings.class); colorSource.addLookupListener(WeakListeners.create(LookupListener.class, this, colorSource)); colorSettings = (FontColorSettings)colorSource.allInstances().iterator().next(); prefs = lkp.lookup(Preferences.class); prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs)); initViewFlags(); }
/** * Creates new instance initializing final fields. */ public AnnotationBar(JTextComponent target) { this.textComponent = target; this.editorUI = Utilities.getEditorUI(target); this.foldHierarchy = FoldHierarchy.get(editorUI.getComponent()); this.doc = editorUI.getDocument(); this.caret = textComponent.getCaret(); setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); elementAnnotationsSubstitute = ""; //NOI18N if (textComponent instanceof JEditorPane) { String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(textComponent); FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); renderingHints = (Map) fcs.getFontColors(FontColorNames.DEFAULT_COLORING).getAttribute(EditorStyleConstants.RenderingHints); } else { renderingHints = null; } }
public static CsmFile getCsmFile(Document bDoc, boolean waitParsing, boolean snapShot) { CsmFile csmFile = null; if (bDoc != null) { try { csmFile = (CsmFile) bDoc.getProperty(CsmFile.class); if (csmFile == null) { csmFile = getCsmFile(NbEditorUtilities.getDataObject(bDoc), waitParsing, snapShot); } if (csmFile == null) { String mimeType = DocumentUtilities.getMimeType(bDoc); if ("text/x-dialog-binding".equals(mimeType)) { // NOI18N // this is context from dialog InputAttributes inputAttributes = (InputAttributes) bDoc.getProperty(InputAttributes.class); if (inputAttributes != null) { LanguagePath path = LanguagePath.get(MimeLookup.getLookup(mimeType).lookup(Language.class)); FileObject fileObject = (FileObject) inputAttributes.getValue(path, "dialogBinding.fileObject"); //NOI18N csmFile = CsmUtilities.getCsmFile(fileObject, waitParsing, snapShot); if (csmFile == null) { Document d = (Document) inputAttributes.getValue(path, "dialogBinding.document"); //NOI18N csmFile = d == null ? null : CsmUtilities.getCsmFile(d, waitParsing, snapShot); } } } } } catch (NullPointerException exc) { exc.printStackTrace(System.err); } } return csmFile; }
public void init(FoldOperation operation) { this.operation = operation; String mimeType = DocumentUtilities.getMimeType(operation.getHierarchy().getComponent()); prefs = MimeLookup.getLookup(mimeType).lookup(Preferences.class); }
if (bDoc != null) { this.csmFile = CsmUtilities.getCsmFile(bDoc, true, false); String mimeType = DocumentUtilities.getMimeType(bDoc); if ("text/x-dialog-binding".equals(mimeType)) { // NOI18N InputAttributes inputAttributes = (InputAttributes) bDoc.getProperty(InputAttributes.class); if (inputAttributes != null) { LanguagePath path = LanguagePath.get(MimeLookup.getLookup(mimeType).lookup(Language.class)); offsetInFile = (Integer) inputAttributes.getValue(path, "dialogBinding.offset"); //NOI18N Integer length = (Integer) inputAttributes.getValue(path, "dialogBinding.length"); //NOI18N
public static int findEndOfMethod(Document doc, int startPos) { int level = 0; CharSequence text = DocumentUtilities.getText(doc); for (int i = startPos; i < doc.getLength(); i++) { char ch = text.charAt(i); if (ch == ';') { return -1; } if (ch == '(') { level++; } if (ch == ')') { level--; if (level == 0) { return i + 1; } } } return -1; }
Position newStartPos = doc.createPosition( firstRegion.getStartOffset() - moveStartDownLength); firstRegion.setStartPosition(newStartPos); int length = region.getEndOffset() - offset; try { final CharSequence old = DocumentUtilities.getText(doc, offset, length); if (!CharSequenceUtilities.textEquals(firstRegionText, old)) { int res = -1; CharSequence remove = old.subSequence(res + 1, old.length()); if (insert.length() > 0) { doc.insertString(offset + res + 1, insert, null); doc.remove(offset + res + 1 + insert.length(), remove.length());
return textToFormat; String mimeType = DocumentUtilities.getMimeType(doc); if (!MIMENames.isHeaderOrCppOrC(mimeType)) { System.err.println("Unsupported MIME type of document " + doc); EditorCookie ec = dob.getLookup().lookup(EditorCookie.class); if (ec != null) { final StyledDocument fmtDoc = ec.openDocument(); ((BaseDocument)fmtDoc).runAtomic(runnable); } else { runnable.run(); fmt.unlock(); SaveCookie save = dob.getLookup().lookup(SaveCookie.class); if (save != null) { save.save();
try { DataObject dobj = DataObject.find(fo); EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class); Document doc = ec.getDocument(); if (doc != null) { String mimeType = DocumentUtilities.getMimeType(doc); if (mimeType != null) { if (MIMENames.isHeaderOrCppOrC(mimeType)) {
private void editorRegistryChanged() { final JTextComponent editor = EditorRegistry.lastFocusedComponent(); final JTextComponent lastEditor = lastEditorRef == null ? null : lastEditorRef.get(); if (lastEditor != editor && (editor == null || editor.getClientProperty("AsTextField") == null)) { if (lastEditor != null) { lastEditor.removeCaretListener(this); lastEditor.removePropertyChangeListener(this); k24.set(false); } lastEditorRef = new WeakReference<JTextComponent>(editor); if (editor != null) { editor.addCaretListener(this); editor.addPropertyChangeListener(this); } final JTextComponent focused = EditorRegistry.focusedComponent(); if (focused != null) { final Document doc = editor.getDocument(); final String mimeType = DocumentUtilities.getMimeType (doc); if (doc != null && mimeType != null) { final Source source = Source.create (doc); if (source != null) { ((EventSupport)SourceEnvironment.forSource(source)).resetState(true, false, -1, -1, true); } } } } }
@Override public void caretUpdate(final CaretEvent event) { final JTextComponent lastEditor = lastEditorRef == null ? null : lastEditorRef.get(); if (lastEditor != null) { Document doc = lastEditor.getDocument (); String mimeType = DocumentUtilities.getMimeType (doc); if (doc != null && mimeType != null) { Source source = Source.create(doc); if (source != null) { ((EventSupport)SourceEnvironment.forSource(source)).resetState(false, false, -1, -1, false); } } } }
private void addHighlightsToBag(PositionsBag bag, List<? extends CsmOffsetable> blocks, SemanticEntity entity) { Document doc = getDocument(); if (doc != null) { String mimeType = DocumentUtilities.getMimeType(doc); if (mimeType == null) { mimeType = MIMENames.CPLUSPLUS_MIME_TYPE; } for (CsmOffsetable block : blocks) { int startOffset = getDocumentOffset(doc, block.getStartOffset()); int endOffset = block.getEndOffset(); endOffset = getDocumentOffset(doc, endOffset == Integer.MAX_VALUE ? doc.getLength() + 1 : endOffset); if (startOffset < doc.getLength() && endOffset > 0) { final AttributeSet attributes = entity.getAttributes(block, mimeType); if (attributes == null) { assert false : "Color attributes set is not found for MIME "+mimeType+". Document "+doc; return; } addHighlightsToBag(bag, startOffset, endOffset, attributes, entity.getName()); } } } }
/** Generic implementation, behaves just as described in specification * in substituteText() - removes <CODE>len</CODE> characters * at <CODE>offset</CODE> out of document and then inserts * whole <CODE>text</CODE>. Ignores <CODE>shift</CODE> argument. */ public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { BaseDocument doc = (BaseDocument)c.getDocument(); try { doc.atomicLock(); try { CharSequence textToReplace = DocumentUtilities.getText(doc, offset, len); if (CharSequenceUtilities.textEquals(text, textToReplace)) return false; doc.remove( offset, len ); doc.insertString( offset, text, null); } finally { doc.atomicUnlock(); } } catch( BadLocationException exc ) { return false; //not sucessfull } return true; }
final TransformationTable tt = new TransformationTable(DocumentUtilities.getDocumentVersion(inDoc), CsmFileInfoQuery.getDefault().getFileVersion(file)); inDoc.render(r); outDoc.putProperty(MACRO_EXPANSION_OFFSET_TRANSFORMER, tt); try { outDoc.insertString(0, expandedData.toString(), null); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex);
if (doc.getProperty(CsmMacroExpansion.MACRO_EXPANSION_VIEW_DOCUMENT) != null) { formatter = new Formatter((BaseDocument) doc); if (tt == null) { if (updateIfNeeded) { tt = new TransformationTable(DocumentUtilities.getDocumentVersion(doc), CsmFileInfoQuery.getDefault().getFileVersion(file)); } else { tt = new TransformationTable(-1, -1); doc.putProperty(MACRO_EXPANSION_MACRO_TABLE, tt); tt = getCachedMacroTable(doc); if (updateIfNeeded) { if (tt.documentVersion != DocumentUtilities.getDocumentVersion(doc) || tt.fileVersion != CsmFileInfoQuery.getDefault().getFileVersion(file)) { tt = new TransformationTable(DocumentUtilities.getDocumentVersion(doc), CsmFileInfoQuery.getDefault().getFileVersion(file)); tt.cleanUp(); synchronized (doc) { doc.putProperty(MACRO_EXPANSION_MACRO_TABLE, tt);