use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class ImplementationViewComponent method update.
public void update(@NotNull final PsiElement[] elements, final int index) {
update(elements, (psiElements, fileDescriptors) -> {
if (myEditor.isDisposed())
return false;
if (psiElements.length == 0)
return false;
final Project project = psiElements[0].getProject();
myElements = psiElements;
myIndex = index < myElements.length ? index : 0;
PsiFile psiFile = getContainingFile(myElements[myIndex]);
VirtualFile virtualFile = psiFile.getVirtualFile();
EditorHighlighter highlighter;
if (virtualFile != null)
highlighter = HighlighterFactory.createHighlighter(project, virtualFile);
else {
// some artificial psi file, lets do best we can
String fileName = psiFile.getName();
highlighter = HighlighterFactory.createHighlighter(project, fileName);
}
((EditorEx) myEditor).setHighlighter(highlighter);
if (myElements.length > 1) {
myFileChooser.setVisible(true);
myCountLabel.setVisible(true);
myLabel.setVisible(false);
myFileChooser.setModel(new DefaultComboBoxModel(fileDescriptors.toArray(new FileDescriptor[fileDescriptors.size()])));
updateRenderer(project);
} else {
myFileChooser.setVisible(false);
myCountLabel.setVisible(false);
VirtualFile file = psiFile.getVirtualFile();
if (file != null) {
myLabel.setIcon(getIconForFile(psiFile));
myLabel.setForeground(FileStatusManager.getInstance(project).getStatus(file).getColor());
myLabel.setText(file.getPresentableName());
myLabel.setBorder(new CompoundBorder(IdeBorderFactory.createRoundedBorder(), IdeBorderFactory.createEmptyBorder(0, 0, 0, 5)));
myLabel.setVisible(true);
}
}
updateControls();
revalidate();
repaint();
return true;
});
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class InspectionResultsView method showInRightPanel.
private void showInRightPanel(@Nullable final RefEntity refEntity) {
Cursor currentCursor = getCursor();
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
final JPanel editorPanel = new JPanel();
editorPanel.setLayout(new BorderLayout());
final int problemCount = myTree.getSelectedProblemCount(true);
JComponent previewPanel = null;
final InspectionToolWrapper tool = myTree.getSelectedToolWrapper(true);
if (tool != null && refEntity != null && refEntity.isValid()) {
final TreePath path = myTree.getSelectionPath();
if (path == null || !(path.getLastPathComponent() instanceof ProblemDescriptionNode)) {
final InspectionToolPresentation presentation = myGlobalInspectionContext.getPresentation(tool);
previewPanel = presentation.getCustomPreviewPanel(refEntity);
}
}
EditorEx previewEditor = null;
if (previewPanel == null) {
final Pair<JComponent, EditorEx> panelAndEditor = createBaseRightComponentFor(problemCount, refEntity);
previewPanel = panelAndEditor.getFirst();
previewEditor = panelAndEditor.getSecond();
}
editorPanel.add(previewPanel, BorderLayout.CENTER);
if (problemCount > 0) {
final JComponent fixToolbar = QuickFixPreviewPanelFactory.create(this);
if (fixToolbar != null) {
if (fixToolbar instanceof InspectionTreeLoadingProgressAware) {
myLoadingProgressPreview = (InspectionTreeLoadingProgressAware) fixToolbar;
}
if (previewEditor != null) {
previewPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
}
editorPanel.add(fixToolbar, BorderLayout.NORTH);
}
}
if (previewEditor != null) {
new ProblemPreviewEditorPresentation(previewEditor, this);
}
mySplitter.setSecondComponent(editorPanel);
} finally {
setCursor(currentCursor);
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class MethodSignatureComponent method setSignature.
public void setSignature(String signature) {
setText(signature);
final EditorEx editor = (EditorEx) getEditor();
if (editor != null) {
editor.getScrollingModel().scrollVertically(0);
editor.getScrollingModel().scrollHorizontally(0);
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class EnterAfterUnmatchedBraceHandler method getUnmatchedLBracesNumberBefore.
/**
* Calculates number of unmatched left braces before the given offset.
*
* @param editor target editor
* @param offset target offset
* @param fileType target file type
* @return number of unmatched braces before the given offset;
* negative value if it's not possible to perform the calculation or if there are no unmatched left braces before
* the given offset
*/
protected static int getUnmatchedLBracesNumberBefore(Editor editor, int offset, FileType fileType) {
if (offset == 0) {
return -1;
}
CharSequence chars = editor.getDocument().getCharsSequence();
if (chars.charAt(offset - 1) != '{') {
return -1;
}
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
if (!braceMatcher.isLBraceToken(iterator, chars, fileType) || !braceMatcher.isStructuralBrace(iterator, chars, fileType)) {
return -1;
}
Language language = iterator.getTokenType().getLanguage();
iterator = highlighter.createIterator(0);
int lBracesBeforeOffset = 0;
int lBracesAfterOffset = 0;
int rBracesBeforeOffset = 0;
int rBracesAfterOffset = 0;
for (; !iterator.atEnd(); iterator.advance()) {
IElementType tokenType = iterator.getTokenType();
if (!tokenType.getLanguage().equals(language) || !braceMatcher.isStructuralBrace(iterator, chars, fileType)) {
continue;
}
boolean beforeOffset = iterator.getStart() < offset;
if (braceMatcher.isLBraceToken(iterator, chars, fileType)) {
if (beforeOffset) {
lBracesBeforeOffset++;
} else {
lBracesAfterOffset++;
}
} else if (braceMatcher.isRBraceToken(iterator, chars, fileType)) {
if (beforeOffset) {
rBracesBeforeOffset++;
} else {
rBracesAfterOffset++;
}
}
}
return lBracesBeforeOffset - rBracesBeforeOffset - (rBracesAfterOffset - lBracesAfterOffset);
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class EnterInLineCommentHandler method isInLineComment.
private static boolean isInLineComment(@NotNull Editor editor, int offset, IElementType lineCommentType) {
if (offset < 1)
return false;
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
return iterator.getTokenType() == lineCommentType;
}
Aggregations