本文整理汇总了Java中org.netbeans.editor.Utilities类的典型用法代码示例。如果您正苦于以下问题:Java Utilities类的具体用法?Java Utilities怎么用?Java Utilities使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Utilities类属于org.netbeans.editor包,在下文中一共展示了Utilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: reindent
import org.netbeans.editor.Utilities; //导入依赖的package包/类
private void reindent(JTextComponent component) {
final BaseDocument doc = (BaseDocument) component.getDocument();
final int dotPos = component.getCaretPosition();
final Indent indent = Indent.get(doc);
indent.lock();
try {
doc.runAtomic(new Runnable() {
@Override
public void run() {
try {
int startOffset = Utilities.getRowStart(doc, dotPos);
int endOffset = Utilities.getRowEnd(doc, dotPos);
indent.reindent(startOffset, endOffset);
} catch (BadLocationException ex) {
//ignore
}
}
});
} finally {
indent.unlock();
}
}
示例3: keyReleased
import org.netbeans.editor.Utilities; //导入依赖的package包/类
public void keyReleased(KeyEvent e) {
// Fix (workaround) for issue #186557
if (org.openide.util.Utilities.isWindows()) {
if (Boolean.getBoolean("HintsUI.disable.AltEnter.hack")) { // NOI18N
return;
}
if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ALT) {
e.consume();
altReleased = true;
} else if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ENTER) {
altEnterPressed = false;
if (altReleased) {
try {
java.awt.Robot r = new java.awt.Robot();
r.keyRelease(KeyEvent.VK_ALT);
} catch (AWTException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
}
示例4: actionPerformed
import org.netbeans.editor.Utilities; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
EditorUI eui = Utilities.getEditorUI(editorPane);
Point location = et.getLocation();
location = eui.getStickyWindowSupport().convertPoint(location);
eui.getToolTipSupport().setToolTipVisible(false);
DebuggerManager dbMgr = DebuggerManager.getDebuggerManager();
BaseDocument document = Utilities.getDocument(editorPane);
DataObject dobj = (DataObject) document.getProperty(Document.StreamDescriptionProperty);
FileObject fo = dobj.getPrimaryFile();
Watch.Pin pin = new EditorPin(fo, pinnable.line, location);
final Watch w = dbMgr.createPinnedWatch(pinnable.expression, pin);
SwingUtilities.invokeLater(() -> {
try {
PinWatchUISupport.getDefault().pin(w, pinnable.valueProviderId);
} catch (IllegalArgumentException ex) {
Exceptions.printStackTrace(ex);
}
});
}
示例5: computeLineSpan
import org.netbeans.editor.Utilities; //导入依赖的package包/类
static int[] computeLineSpan(Document doc, int lineNumber) throws BadLocationException {
lineNumber = Math.min(lineNumber, NbDocument.findLineRootElement((StyledDocument) doc).getElementCount());
int lineStartOffset = NbDocument.findLineOffset((StyledDocument) doc, Math.max(0, lineNumber - 1));
int lineEndOffset;
if (doc instanceof BaseDocument) {
lineEndOffset = Utilities.getRowEnd((BaseDocument) doc, lineStartOffset);
} else {
//XXX: performance:
String lineText = doc.getText(lineStartOffset, doc.getLength() - lineStartOffset);
lineText = lineText.indexOf('\n') != (-1) ? lineText.substring(0, lineText.indexOf('\n')) : lineText;
lineEndOffset = lineStartOffset + lineText.length();
}
int[] span = new int[] {lineStartOffset, lineEndOffset};
computeLineSpan(doc, span);
return span;
}
示例6: getOffsetForPoint
import org.netbeans.editor.Utilities; //导入依赖的package包/类
private static int getOffsetForPoint(Point p, JTextComponent c, BaseDocument doc) throws BadLocationException {
if (p.x >= 0 && p.y >= 0) {
int offset = c.viewToModel(p);
Rectangle r = c.modelToView(offset);
EditorUI eui = Utilities.getEditorUI(c);
// Check that p is on a line with text and not completely below text,
// ie. behind EOF.
int relY = p.y - r.y;
if (eui != null && relY < eui.getLineHeight()) {
// Check that p is on a line with text before its EOL.
if (offset < Utilities.getRowEnd(doc, offset)) {
return offset;
}
}
}
return -1;
}
示例7: AnnotationBar
import org.netbeans.editor.Utilities; //导入依赖的package包/类
/**
* 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();
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;
}
setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
elementAnnotationsSubstitute = ""; //NOI18N
}
示例8: getInitialIndentFromPreviousLine
import org.netbeans.editor.Utilities; //导入依赖的package包/类
protected int getInitialIndentFromPreviousLine(final BaseDocument doc, final int line) throws BadLocationException {
// get initial indent from the previous line
int initialIndent = 0;
if (line > 0) {
int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
int previousNonWhiteLineEnd = Utilities.getFirstNonWhiteBwd(doc, lineStart);
if (previousNonWhiteLineEnd > 0) {
initialIndent = Utilities.getRowIndent(doc, previousNonWhiteLineEnd);
}
}
return initialIndent;
}
示例9: gotoDeclaration
import org.netbeans.editor.Utilities; //导入依赖的package包/类
public boolean gotoDeclaration(JTextComponent target) {
BaseDocument doc = Utilities.getDocument(target);
if (doc == null)
return false;
try {
Caret caret = target.getCaret();
int dotPos = caret.getDot();
int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos);
ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport();
if (idBlk != null) {
int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]);
if (decPos >= 0) {
caret.setDot(decPos);
return true;
}
}
} catch (BadLocationException e) {
}
return false;
}
示例10: 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);
}
}
示例11: getInitialIndentFromPreviousLine
import org.netbeans.editor.Utilities; //导入依赖的package包/类
protected int getInitialIndentFromPreviousLine(final BaseDocument doc, final int line) throws BadLocationException {
// get initial indent from the previous line
int initialIndent = 0;
if (line > 0){
int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
int previousNonWhiteLineEnd = Utilities.getFirstNonWhiteBwd(doc, lineStart);
if (previousNonWhiteLineEnd > 0){
initialIndent = Utilities.getRowIndent(doc, previousNonWhiteLineEnd);
}
}
return initialIndent;
}
示例12: 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;
}
}
示例13: getIdentifierUnderCursor
import org.netbeans.editor.Utilities; //导入依赖的package包/类
/** Helper method to get the identifier
* under the mouse cursor.
* @return string containing identifier under
* mouse cursor.
*/
public String getIdentifierUnderCursor() {
String word = null;
if (!isGlyphGutterMouseEvent(lastMouseEvent)) {
try {
JTextComponent component = extEditorUI.getComponent();
BaseTextUI ui = (BaseTextUI)component.getUI();
Point lmePoint = getLastMouseEventPoint();
int pos = ui.viewToModel(component, lmePoint);
if (pos >= 0) {
BaseDocument doc = (BaseDocument)component.getDocument();
int eolPos = Utilities.getRowEnd(doc, pos);
Rectangle eolRect = ui.modelToView(component, eolPos);
int lineHeight = extEditorUI.getLineHeight();
if (lmePoint.x <= eolRect.x && lmePoint.y <= eolRect.y + lineHeight) {
word = Utilities.getIdentifier(doc, pos);
}
}
} catch (BadLocationException e) {
// word will be null
}
}
return word;
}
示例14: addClassNameEditorCC
import org.netbeans.editor.Utilities; //导入依赖的package包/类
static Pair<JScrollPane, JEditorPane> addClassNameEditorCC(String mimeType, JComponent comp, String className, String tooltipText) {
JComponent [] editorComponents = Utilities.createSingleLineEditor(mimeType);
JScrollPane sle = (JScrollPane) editorComponents[0];
JEditorPane epClassName = (JEditorPane) editorComponents[1];
epClassName.setText(className);
if (comp != null) {
java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
comp.add(sle, gridBagConstraints);
}
sle.setToolTipText(tooltipText);
epClassName.setToolTipText(tooltipText);
return Pair.<JScrollPane, JEditorPane>of(sle, epClassName);
}
示例15: modifyLine
import org.netbeans.editor.Utilities; //导入依赖的package包/类
private void modifyLine(BaseDocument doc, String mimeType, int offset) throws BadLocationException {
Feature feature = null;
try {
Language language = LanguagesManager.getDefault().getLanguage(mimeType);
feature = language.getFeatureList ().getFeature (COMMENT_LINE);
} catch (LanguageDefinitionNotFoundException e) {
}
if (feature != null) {
String prefix = (String) feature.getValue("prefix"); // NOI18N
if (prefix == null) {
return;
}
String suffix = (String) feature.getValue("suffix"); // NOI18N
if (suffix != null) {
int end = Utilities.getRowEnd(doc, offset);
doc.insertString(end, suffix, null);
}
doc.insertString(offset, prefix, null);
}
}