本文整理汇总了Java中com.intellij.openapi.editor.ex.util.EditorUtil类的典型用法代码示例。如果您正苦于以下问题:Java EditorUtil类的具体用法?Java EditorUtil怎么用?Java EditorUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EditorUtil类属于com.intellij.openapi.editor.ex.util包,在下文中一共展示了EditorUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testSoftWrapsRecalculationInASpecificCase
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
public void testSoftWrapsRecalculationInASpecificCase() throws Exception {
configureFromFileText(getTestName(false) + ".java",
"<selection>class Foo {\n" +
"\[email protected]\n" +
"\tpublic boolean equals(Object other) {\n" +
"\t\treturn this == other;\n" +
"\t}\n" +
"}</selection>");
CodeFoldingManager.getInstance(ourProject).buildInitialFoldings(myEditor);
EditorTestUtil.configureSoftWraps(myEditor, 232, 7); // wrap after 32 characters
// verify initial state
assertEquals(4, EditorUtil.getTabSize(myEditor));
assertEquals("[FoldRegion +(59:64), placeholder=' { ', FoldRegion +(85:88), placeholder=' }']", myEditor.getFoldingModel().toString());
verifySoftWrapPositions(52, 85);
Document document = myEditor.getDocument();
for (int i = document.getLineCount() - 1; i >= 0; i--) {
document.insertString(document.getLineStartOffset(i), "//");
}
verifySoftWrapPositions(58, 93);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:EditorImplTest.java
示例2: paintAfterLineEndBackgroundSegments
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private void paintAfterLineEndBackgroundSegments(@NotNull Graphics g,
@NotNull IterationState iterationState,
@NotNull Point position,
@NotNull Color defaultBackground,
int lineHeight) {
while (iterationState.hasPastLineEndBackgroundSegment()) {
TextAttributes backgroundAttributes = iterationState.getPastLineEndBackgroundAttributes();
int width = EditorUtil.getSpaceWidth(backgroundAttributes.getFontType(), this) * iterationState.getPastLineEndBackgroundSegmentWidth();
Color color = getBackgroundColor(backgroundAttributes);
if (color != null && !color.equals(defaultBackground)) {
g.setColor(color);
g.fillRect(position.x, position.y, width, lineHeight);
}
position.x += width;
iterationState.advanceToNextPastLineEndBackgroundSegment();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:bigFile.java
示例3: getTextSegmentWidth
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private int getTextSegmentWidth(@NotNull CharSequence text,
int start,
int end,
int xStart,
@JdkConstants.FontStyle int fontType,
@NotNull Rectangle clip) {
int x = xStart;
for (int i = start; i < end && xStart < clip.x + clip.width; i++) {
char c = text.charAt(i);
if (c == '\t') {
x = EditorUtil.nextTabStop(x, this);
}
else {
x += EditorUtil.charWidth(c, fontType, this);
}
if (x > clip.x + clip.width) {
break;
}
}
return x - xStart;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:bigFile.java
示例4: getPreferredSize
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
public Dimension getPreferredSize() {
if (myUseNewRendering) return myView.getPreferredSize();
if (ourIsUnitTestMode && getUserData(DO_DOCUMENT_UPDATE_TEST) == null) {
return new Dimension(1, 1);
}
final Dimension draft = getSizeWithoutCaret();
final int additionalSpace = shouldRespectAdditionalColumns()
? mySettings.getAdditionalColumnsCount() * EditorUtil.getSpaceWidth(Font.PLAIN, this)
: 0;
if (!myDocument.isInBulkUpdate()) {
for (Caret caret : myCaretModel.getAllCarets()) {
if (caret.isUpToDate()) {
int caretX = visualPositionToXY(caret.getVisualPosition()).x;
draft.width = Math.max(caretX, draft.width);
}
}
}
draft.width += additionalSpace;
return draft;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:bigFile.java
示例5: setPrefixTextAndAttributes
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
@Override
public void setPrefixTextAndAttributes(@Nullable String prefixText, @Nullable TextAttributes attributes) {
myPrefixText = prefixText == null ? null : prefixText.toCharArray();
myPrefixAttributes = attributes;
myPrefixWidthInPixels = 0;
if (myPrefixText != null) {
for (char c : myPrefixText) {
LOG.assertTrue(myPrefixAttributes != null);
if (myPrefixAttributes != null) {
myPrefixWidthInPixels += EditorUtil.charWidth(c, myPrefixAttributes.getFontType(), this);
}
}
}
mySoftWrapModel.recalculate();
if (myUseNewRendering) myView.setPrefix(prefixText, attributes);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:bigFile.java
示例6: reinitSettings
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
/**
* Called on editor settings change. Current model is expected to drop all cached information about the settings if any.
*/
public void reinitSettings() {
boolean softWrapsUsedBefore = myUseSoftWraps;
myUseSoftWraps = areSoftWrapsEnabledInEditor();
int tabWidthBefore = myTabWidth;
myTabWidth = EditorUtil.getTabSize(myEditor);
boolean fontsChanged = false;
if (!myFontPreferences.equals(myEditor.getColorsScheme().getFontPreferences())
&& myEditorTextRepresentationHelper instanceof DefaultEditorTextRepresentationHelper) {
fontsChanged = true;
myEditor.getColorsScheme().getFontPreferences().copyTo(myFontPreferences);
((DefaultEditorTextRepresentationHelper)myEditorTextRepresentationHelper).clearSymbolWidthCache();
myPainter.reinit();
}
if ((myUseSoftWraps ^ softWrapsUsedBefore) || (tabWidthBefore >= 0 && myTabWidth != tabWidthBefore) || fontsChanged) {
myApplianceManager.reset();
myDeferredFoldRegions.clear();
myStorage.removeAll();
myEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:SoftWrapModelImpl.java
示例7: getMaxWidthInRange
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
@Override
public int getMaxWidthInRange(int startOffset, int endOffset) {
if (myUseNewRendering) return myView.getMaxWidthInRange(startOffset, endOffset);
int width = 0;
int start = offsetToVisualLine(startOffset);
int end = offsetToVisualLine(endOffset);
for (int i = start; i <= end; i++) {
int lastColumn = EditorUtil.getLastVisualLineColumnNumber(this, i) + 1;
int lineWidth = visualPositionToXY(new VisualPosition(i, lastColumn)).x;
if (lineWidth > width) {
width = lineWidth;
}
}
return width;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:bigFile.java
示例8: paintAfterLineEndBackgroundSegments
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private void paintAfterLineEndBackgroundSegments(@NotNull Graphics g,
@NotNull IterationState iterationState,
@NotNull Point position,
@NotNull Color defaultBackground,
int lineHeight) {
while (iterationState.hasPastLineEndBackgroundSegment()) {
TextAttributes backgroundAttributes = iterationState.getPastLineEndBackgroundAttributes();
int width =
EditorUtil.getSpaceWidth(backgroundAttributes.getFontType(), this) * iterationState.getPastLineEndBackgroundSegmentWidth();
Color color = getBackgroundColor(backgroundAttributes);
if (color != null && !color.equals(defaultBackground)) {
g.setColor(color);
g.fillRect(position.x, position.y, width, lineHeight);
}
position.x += width;
iterationState.advanceToNextPastLineEndBackgroundSegment();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:bigFile.java
示例9: ConsoleGutterComponent
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
public ConsoleGutterComponent(@NotNull Editor editor, @NotNull GutterContentProvider gutterContentProvider, boolean atLineStart) {
this.editor = (EditorImpl)editor;
this.gutterContentProvider = gutterContentProvider;
this.atLineStart = atLineStart;
if (atLineStart) {
setOpaque(gutterContentProvider.getLineStartGutterOverlap(editor) == 0);
}
else {
addListeners();
setOpaque(false);
}
int spaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, editor);
// at line start: icon/one-char symbol + space
gap = atLineStart ? spaceWidth * GutterContentProvider.MAX_LINE_END_GUTTER_WIDTH_IN_CHAR : spaceWidth;
maxContentWidth = atLineStart ? gap : 0;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ConsoleGutterComponent.java
示例10: drawCharsCached
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private void drawCharsCached(@NotNull Graphics g,
CharSequence data,
int start,
int end,
int x,
int y,
@JdkConstants.FontStyle int fontType,
Color color,
boolean drawWhitespace) {
FontInfo fnt = EditorUtil.fontForChar(data.charAt(start), fontType, this);
if (myLastCache != null && spacesOnly(data, start, end) && fnt.charWidth(' ') == myLastCache.spaceWidth) {
// we don't care about font if we only need to paint spaces and space width matches
myLastCache.addContent(g, data, start, end, x, y, null, drawWhitespace);
}
else {
drawCharsCached(g, data, start, end, x, y, fnt, color, drawWhitespace);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:bigFile.java
示例11: tweakEditorAndFireUpdateUI
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private static void tweakEditorAndFireUpdateUI(UISettings settings, boolean inPresentation) {
EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
int fontSize = inPresentation ? settings.PRESENTATION_MODE_FONT_SIZE : globalScheme.getEditorFontSize();
if (inPresentation) {
ourSavedConsoleFontSize = globalScheme.getConsoleFontSize();
globalScheme.setConsoleFontSize(fontSize);
}
else {
globalScheme.setConsoleFontSize(ourSavedConsoleFontSize);
}
for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
if (editor instanceof EditorEx) {
((EditorEx)editor).setFontSize(fontSize);
}
}
UISettings.getInstance().fireUISettingsChanged();
LafManager.getInstance().updateUI();
EditorUtil.reinitSettings();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:TogglePresentationModeAction.java
示例12: actionPerformed
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
if (project == null || editor == null || virtualFile == null) return;
final Document document = editor.getDocument();
final TextRange selectedRange = EditorUtil.getSelectionInAnyMode(editor);
final String command = (selectedRange.isEmpty() ? document.getText() : document.getText(selectedRange));
final GroovyConsole existingConsole = virtualFile.getUserData(GroovyConsole.GROOVY_CONSOLE);
if (existingConsole == null) {
GroovyConsole.getOrCreateConsole(project, virtualFile, new Consumer<GroovyConsole>() {
@Override
public void consume(GroovyConsole console) {
console.execute(command);
}
});
}
else {
existingConsole.execute(command);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GrExecuteCommandAction.java
示例13: checkResultByFile
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private void checkResultByFile(@NonNls @NotNull String expectedFile,
@NotNull PsiFile originalFile,
boolean stripTrailingSpaces) throws IOException {
if (!stripTrailingSpaces) {
EditorUtil.fillVirtualSpaceUntilCaret(myEditor);
}
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
final String fileText = originalFile.getText();
final String path = getTestDataPath() + "/" + expectedFile;
/*final VirtualFile result = LocalFileSystem.getInstance().findFileByPath(path);
final int caret = myEditor.getCaretModel().getOffset();
final String newText = myFile == originalFile ? fileText.substring(0, caret) + "<caret>" + fileText.substring(caret) : fileText;
VfsUtil.saveText(result, newText);*/
VirtualFile virtualFile = originalFile.getVirtualFile();
String charset = virtualFile == null? null : virtualFile.getCharset().name();
checkResult(expectedFile, stripTrailingSpaces, SelectionAndCaretMarkupLoader.fromFile(path, charset), fileText);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CodeInsightTestFixtureImpl.java
示例14: visualLineStartOffset
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private int visualLineStartOffset(int offset, boolean leanForward) {
EditorImpl editor = myView.getEditor();
int result = EditorUtil.getNotFoldedLineStartOffset(editor, offset);
SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps();
int currentOrPrevWrapIndex = softWrapModel.getSoftWrapIndex(offset);
SoftWrap currentOrPrevWrap;
if (currentOrPrevWrapIndex < 0) {
currentOrPrevWrapIndex = - currentOrPrevWrapIndex - 2;
currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null :
softWraps.get(currentOrPrevWrapIndex);
}
else {
currentOrPrevWrap = leanForward ? softWraps.get(currentOrPrevWrapIndex) : null;
}
if (currentOrPrevWrap != null && currentOrPrevWrap.getStart() > result) {
result = currentOrPrevWrap.getStart();
}
return result;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:EditorCoordinateMapper.java
示例15: doSelectLineAtCaret
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
public static void doSelectLineAtCaret(Editor editor) {
int lineNumber = editor.getCaretModel().getLogicalPosition().line;
Document document = editor.getDocument();
if (lineNumber >= document.getLineCount()) {
return;
}
Pair<LogicalPosition, LogicalPosition> lines = EditorUtil.calcCaretLineRange(editor);
LogicalPosition lineStart = lines.first;
LogicalPosition nextLineStart = lines.second;
int start = editor.logicalPositionToOffset(lineStart);
int end = editor.logicalPositionToOffset(nextLineStart);
//myEditor.getCaretModel().moveToOffset(start);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
editor.getSelectionModel().setSelection(start, end);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:SelectionModelImpl.java
示例16: calcAnnotationExtraSize
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private void calcAnnotationExtraSize() {
myTextAnnotationExtraSize = 0;
if (!myEditor.isInDistractionFreeMode() || isMirrored()) return;
Window frame = SwingUtilities.getWindowAncestor(myEditor.getComponent());
if (frame == null) return;
EditorSettings settings = myEditor.getSettings();
int rightMargin = settings.getRightMargin(myEditor.getProject());
if (rightMargin <= 0) return;
JComponent editorComponent = myEditor.getComponent();
RelativePoint point = new RelativePoint(editorComponent, new Point(0, 0));
Point editorLocationInWindow = point.getPoint(frame);
int editorLocationX = (int)editorLocationInWindow.getX();
int rightMarginX = rightMargin * EditorUtil.getSpaceWidth(Font.PLAIN, myEditor) + editorLocationX;
int width = editorLocationX + editorComponent.getWidth();
if (rightMarginX < width && editorLocationX < width - rightMarginX) {
int centeredSize = (width - rightMarginX - editorLocationX) / 2 - (getLineMarkerAreaWidth() + getLineNumberAreaWidth());
myTextAnnotationExtraSize = Math.max(0, centeredSize - myTextAnnotationGuttersSize);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:EditorGutterComponentImpl.java
示例17: reinit
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
/**
* Tries to find fonts that are capable to display all unicode symbols used by the current painter.
*/
@Override
public void reinit() {
// We use dummy component here in order to being able to work with font metrics.
JLabel component = new JLabel();
myCanUse = true;
for (Map.Entry<SoftWrapDrawingType, char[]> entry : mySymbols.entrySet()) {
SoftWrapDrawingType type = entry.getKey();
char c = entry.getValue()[0];
FontInfo fontInfo = EditorUtil.fontForChar(c, Font.PLAIN, myEditor);
if (!fontInfo.canDisplay(c)) {
myCanUse = false;
myFonts.put(type, null);
myVGaps.put(type, null);
myWidths[type.ordinal()] = 0;
}
else {
myFonts.put(type, fontInfo);
FontMetrics metrics = component.getFontMetrics(fontInfo.getFont());
myWidths[type.ordinal()] = metrics.charWidth(c);
int vGap = metrics.getDescent();
myVGaps.put(type, vGap);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:TextBasedSoftWrapPainter.java
示例18: getFontAbleToDisplay
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
@Nullable
Font getFontAbleToDisplay(LookupElementPresentation p) {
String sampleString = p.getItemText() + p.getTailText() + p.getTypeText();
// assume a single font can display all lookup item chars
Set<Font> fonts = ContainerUtil.newHashSet();
for (int i = 0; i < sampleString.length(); i++) {
fonts.add(EditorUtil.fontForChar(sampleString.charAt(i), Font.PLAIN, myLookup.getEditor()).getFont());
}
eachFont: for (Font font : fonts) {
if (font.equals(myNormalFont)) continue;
for (int i = 0; i < sampleString.length(); i++) {
if (!font.canDisplay(sampleString.charAt(i))) {
continue eachFont;
}
}
return font;
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:LookupCellRenderer.java
示例19: invoke
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, final Editor editor, PsiFile file) {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
PsiReferenceExpression[] refs = CreateFromUsageUtils.collectExpressions(myRefExpr, PsiMember.class, PsiFile.class);
PsiElement element = PsiTreeUtil.getParentOfType(myRefExpr, PsiMember.class, PsiFile.class);
LookupElement[] items = collectItems();
ReferenceNameExpression refExpr = new ReferenceNameExpression(items, myRefExpr.getReferenceName());
TemplateBuilderImpl builder = new TemplateBuilderImpl(element);
for (PsiReferenceExpression expr : refs) {
if (!expr.equals(myRefExpr)) {
builder.replaceElement(expr.getReferenceNameElement(), OTHER_VARIABLE_NAME, INPUT_VARIABLE_NAME, false);
}
else {
builder.replaceElement(expr.getReferenceNameElement(), INPUT_VARIABLE_NAME, refExpr, true);
}
}
final float proportion = EditorUtil.calcVerticalScrollProportion(editor);
editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());
/*for (int i = refs.length - 1; i >= 0; i--) {
TextRange range = refs[i].getReferenceNameElement().getTextRange();
document.deleteString(range.getStartOffset(), range.getEndOffset());
}
*/
Template template = builder.buildInlineTemplate();
editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());
TemplateManager.getInstance(project).startTemplate(editor, template);
EditorUtil.setVerticalScrollProportion(editor, proportion);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:RenameWrongRefFix.java
示例20: initTabPainter
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入依赖的package包/类
private void initTabPainter() {
myTabPainter = new ArrowPainter(
ColorProvider.byColorsScheme(myScheme, EditorColors.WHITESPACES_COLOR),
new Computable.PredefinedValueComputable<Integer>(EditorUtil.getSpaceWidth(Font.PLAIN, this)),
new Computable<Integer>() {
@Override
public Integer compute() {
return getCharHeight();
}
}
);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:bigFile.java
注:本文中的com.intellij.openapi.editor.ex.util.EditorUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论