本文整理汇总了Java中org.netbeans.editor.Utilities.getRowFirstNonWhite方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.getRowFirstNonWhite方法的具体用法?Java Utilities.getRowFirstNonWhite怎么用?Java Utilities.getRowFirstNonWhite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.editor.Utilities
的用法示例。
在下文中一共展示了Utilities.getRowFirstNonWhite方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateHighlightsOnLine
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
static void updateHighlightsOnLine(OffsetsBag bag, BaseDocument doc, Position line, List<ErrorDescription> errorDescriptions) throws IOException {
try {
int rowStart = line.getOffset();
int rowEnd = Utilities.getRowEnd(doc, rowStart);
int rowHighlightStart = Utilities.getRowFirstNonWhite(doc, rowStart);
int rowHighlightEnd = Utilities.getRowLastNonWhite(doc, rowStart) + 1;
if (rowStart <= rowEnd) {
bag.removeHighlights(rowStart, rowEnd, false);
}
if (errorDescriptions != null) {
bag.addAllHighlights(computeHighlights(doc, errorDescriptions).getHighlights(rowHighlightStart, rowHighlightEnd));
}
} catch (BadLocationException ex) {
throw new IOException(ex);
}
}
示例2: allComments
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private boolean allComments(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException {
for (int offset = startOffset; lineCount > 0; lineCount--) {
int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
if (firstNonWhitePos == -1) {
return false;
}
if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos < lineCommentStringLen) {
return false;
}
CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen);
if (!CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) {
return false;
}
offset = Utilities.getRowStart(doc, offset, +1);
}
return true;
}
示例3: uncomment
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void uncomment(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException {
for (int offset = startOffset; lineCount > 0; lineCount--) {
// Get the first non-whitespace char on the current line
int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
// If there is any, check wheter it's the line-comment-chars and remove them
if (firstNonWhitePos != -1) {
if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= lineCommentStringLen) {
CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen);
if (CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) {
doc.remove(firstNonWhitePos, lineCommentStringLen);
}
}
}
offset = Utilities.getRowStart(doc, offset, +1);
}
}
示例4: generateBasicLine
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private Line generateBasicLine(int index) throws BadLocationException {
Line line = new Line();
line.index = index;
line.offset = Utilities.getRowStartFromLineOffset(getDocument(), index);
line.existingLineIndent = IndentUtils.lineIndent(getDocument(), line.offset);
int nonWS = Utilities.getRowFirstNonWhite(getDocument(), line.offset);
line.emptyLine = nonWS == -1;
// if (first-non-whitespace-offset - line-start-offset) is different from
// existingLineIndent then line starts with tab characters which will need
// to be replaced; if line is empty set tabIndentation to true just to make sure
// possible tabs get replaced:
line.tabIndentation = nonWS == -1 || line.existingLineIndent != (nonWS - line.offset);
line.lineStartOffset = line.offset;
line.lineEndOffset = Utilities.getRowEnd(getDocument(), line.offset);
line.lineIndent = new ArrayList<IndentCommand>();
line.lineIndent.add(new IndentCommand(IndentCommand.Type.NO_CHANGE, line.offset, getIndentationSize()));
line.preliminaryNextLineIndent = new ArrayList<IndentCommand>();
line.preliminaryNextLineIndent.add(new IndentCommand(IndentCommand.Type.NO_CHANGE, line.offset, getIndentationSize()));
return line;
}
示例5: allComments
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private boolean allComments(BaseDocument doc, int startOffset, int lineCount, String lineCommentString) throws BadLocationException {
final int lineCommentStringLen = lineCommentString.length();
for (int offset = startOffset; lineCount > 0; lineCount--) {
int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
if (firstNonWhitePos == -1) {
return false;
}
if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos < lineCommentStringLen) {
return false;
}
CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen);
if (!CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) {
return false;
}
offset = Utilities.getRowStart(doc, offset, +1);
}
return true;
}
示例6: uncomment
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void uncomment(BaseDocument doc, int startOffset, int lineCount, String lineCommentString) throws BadLocationException {
final int lineCommentStringLen = lineCommentString.length();
for (int offset = startOffset; lineCount > 0; lineCount--) {
// Get the first non-whitespace char on the current line
int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
// If there is any, check wheter it's the line-comment-chars and remove them
if (firstNonWhitePos != -1) {
if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= lineCommentStringLen) {
CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen);
if (CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) {
doc.remove(firstNonWhitePos, lineCommentStringLen);
}
}
}
offset = Utilities.getRowStart(doc, offset, +1);
}
}
示例7: getLineIndent
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public static int getLineIndent(BaseDocument doc, int offset) {
try {
int start = Utilities.getRowStart(doc, offset);
int end;
if (Utilities.isRowWhite(doc, start)) {
end = Utilities.getRowEnd(doc, offset);
} else {
end = Utilities.getRowFirstNonWhite(doc, start);
}
int indent = Utilities.getVisualColumn(doc, end);
return indent;
} catch (BadLocationException ble) {
Exceptions.printStackTrace(ble);
return 0;
}
}
示例8: doesLineStartWithOurLanguage
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private boolean doesLineStartWithOurLanguage(BaseDocument doc, int lineIndex, JoinedTokenSequence<T1> joinedTS) throws BadLocationException {
int rowStartOffset = Utilities.getRowStartFromLineOffset(doc, lineIndex);
int rowEndOffset = Utilities.getRowEnd(doc, rowStartOffset);
int firstNonWhite = Utilities.getRowFirstNonWhite(doc, rowStartOffset);
if (firstNonWhite != -1) {
// there is something on the line:
int newRowStartOffset = findLanguageOffset(joinedTS, rowStartOffset, rowEndOffset, true);
if (newRowStartOffset == -1) {
// but it is not our langauge
return false;
}
}
return true;
}
示例9: afterInsert
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void afterInsert(Context context) throws BadLocationException {
char ch = context.getText().charAt(0);
if ('}' == ch) {
final int lineStart = Utilities.getRowFirstNonWhite((BaseDocument) context.getDocument(), context.getOffset());
if (lineStart == context.getOffset()) {
reindentLater((BaseDocument) context.getDocument(), context.getOffset(), context.getOffset());
}
}
}
示例10: hasTextBefore
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected boolean hasTextBefore(JTextComponent target, String typedText) {
BaseDocument doc = Utilities.getDocument(target);
int dotPos = target.getCaret().getDot();
try {
int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
return dotPos != fnw+typedText.length();
} catch (BadLocationException e) {
return false;
}
}
示例11: actionPerformed
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
Caret caret = target.getCaret();
BaseDocument doc = (BaseDocument)target.getDocument();
try {
int dot = caret.getDot();
// #232675: if bounds are defined, use them rather than line start/end
Object o = target.getClientProperty(PROP_NAVIGATE_BOUNDARIES);
PositionRegion bounds = null;
int lineStartPos = Utilities.getRowStart(target, dot);
if (o instanceof PositionRegion) {
bounds = (PositionRegion)o;
int start = bounds.getStartOffset();
int end = bounds.getEndOffset();
int boundLineStart = Utilities.getRowStart(target, start);
// refinement: only use the boundaries if the caret is at the same line
// as boundary start; otherwise ignore the boundary and use document lines.
if (boundLineStart == lineStartPos && dot > start && dot <= end) {
// move to the region start
dot = start;
} else {
bounds = null;
}
}
if (bounds == null) {
if (homeKeyColumnOne) { // to first column
dot = lineStartPos;
} else { // either to line start or text start
int textStartPos = Utilities.getRowFirstNonWhite(doc, lineStartPos);
if (textStartPos < 0) { // no text on the line
textStartPos = Utilities.getRowEnd(target, lineStartPos);
}
if (dot == lineStartPos) { // go to the text start pos
dot = textStartPos;
} else if (dot <= textStartPos) {
dot = lineStartPos;
} else {
dot = textStartPos;
}
}
}
// For partial view hierarchy check bounds
dot = Math.max(dot, target.getUI().getRootView(target).getStartOffset());
String actionName = (String) getValue(Action.NAME);
boolean select = selectionBeginLineAction.equals(actionName)
|| selectionLineFirstColumnAction.equals(actionName);
// If possible scroll the view to its begining horizontally
// to ease user's orientation in the code.
Rectangle r = target.modelToView(dot);
Rectangle visRect = target.getVisibleRect();
if (r.getMaxX() < visRect.getWidth()) {
r.x = 0;
target.scrollRectToVisible(r);
}
target.putClientProperty("navigational.action", SwingConstants.WEST);
if (select) {
caret.moveDot(dot);
} else {
caret.setDot(dot);
}
} catch (BadLocationException e) {
target.getToolkit().beep();
}
}
}
示例12: tryReplaceTab
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void tryReplaceTab() throws BadLocationException {
int rowFirstNonWhite = Utilities.getRowFirstNonWhite(baseDocument, caretOffset);
if (shouldBeReplaced(rowFirstNonWhite, caretOffset)) {
replaceTab();
}
}
示例13: create
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public static WhereUsedElement create(FileObject fileObject, String name, OffsetRange range, ElementKind kind) {
Icon icon = UiUtils.getElementIcon(kind, Collections.<Modifier>emptyList());
int start = range.getStart();
int end = range.getEnd();
int sta = start;
int en = start; // ! Same line as start
String content = null;
BaseDocument bdoc = GsfUtilities.getDocument(fileObject, true);
StringBuilder displayText = new StringBuilder();
try {
bdoc.readLock();
// I should be able to just call tree.getInfo().getText() to get cached
// copy - but since I'm playing fast and loose with compilationinfos
// for for example find subclasses (using a singly dummy FileInfo) I need
// to read it here instead
content = bdoc.getText(0, bdoc.getLength());
sta = Utilities.getRowFirstNonWhite(bdoc, start);
if (sta == -1) {
sta = Utilities.getRowStart(bdoc, start);
}
en = Utilities.getRowLastNonWhite(bdoc, start);
if (en == -1) {
en = Utilities.getRowEnd(bdoc, start);
} else {
// Last nonwhite - left side of the last char, not inclusive
en++;
}
// Sometimes the node we get from the AST is for the whole block
// (e.g. such as the whole class), not the argument node. This happens
// for example in Find Subclasses out of the index. In this case
if (end > en) {
end = start + name.length();
if (end > bdoc.getLength()) {
end = bdoc.getLength();
}
}
} catch (Exception ex) {
content = "n/a"; //NOI18N
Exceptions.printStackTrace(ex);
} finally {
bdoc.readUnlock();
}
if (end < sta) {
// XXX Shouldn't happen, but I still have AST offset errors
sta = end;
}
if (start < sta) {
// XXX Shouldn't happen, but I still have AST offset errors
start = sta;
}
if (en < end) {
// XXX Shouldn't happen, but I still have AST offset errors
en = end;
}
displayText.append(encodeCharRefs(content.subSequence(sta, start).toString()));
displayText.append("<b>"); // NOI18N
displayText.append(content.subSequence(start, end));
displayText.append("</b>"); // NOI18N
displayText.append(encodeCharRefs(content.subSequence(end, en).toString()));
CloneableEditorSupport ces = GsfUtilities.findCloneableEditorSupport(fileObject);
PositionRef ref1 = ces.createPositionRef(start, Bias.Forward);
PositionRef ref2 = ces.createPositionRef(end, Bias.Forward);
PositionBounds bounds = new PositionBounds(ref1, ref2);
return new WhereUsedElement(bounds, displayText.toString().trim(),
fileObject, name, new OffsetRange(start, end), icon);
}
示例14: Highlights
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private Highlights(long version, int startOffset, int endOffset, FileCoverageDetails details) {
this.version = version;
this.startOffsetBoundary = startOffset;
this.endOffsetBoundary = endOffset;
if (lastPositions == null) {
positions = new ArrayList<Position>();
types = new ArrayList<CoverageType>();
for (int lineno = 0, maxLines = details.getLineCount(); lineno < maxLines; lineno++) {
CoverageType type = details.getType(lineno);
if (type == CoverageType.COVERED || type == CoverageType.INFERRED ||
type == CoverageType.NOT_COVERED || type == CoverageType.PARTIAL) {
try {
int offset = Utilities.getRowStartFromLineOffset(doc, lineno);
if (offset == -1) {
continue;
}
// Attach the highlight position to the beginning of text, such
// that if we insert a new line at the beginning of a line (or in
// the whitespace region) the highlight will move down with the
// text
int rowStart = Utilities.getRowFirstNonWhite(doc, offset);
if (rowStart != -1) {
offset = rowStart;
}
Position pos = doc.createPosition(offset, Position.Bias.Forward);
positions.add(pos);
types.add(type);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
}
lastPositions = positions;
lastTypes = types;
} else {
positions = lastPositions;
types = lastTypes;
}
try {
int lineStart = Utilities.getRowFirstNonWhite(doc, startOffsetBoundary);
if (lineStart == -1) {
lineStart = Utilities.getRowStart(doc, startOffsetBoundary);
index = findPositionIndex(positions, lineStart);
if (index < 0) {
index = -index;
}
}
} catch (BadLocationException ble) {
}
}