use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class CCShowPreview method showPreviewDialog.
private static void showPreviewDialog(@NotNull Project project, @NotNull VirtualFile userFile, @NotNull TaskFile taskFile) {
final FrameWrapper showPreviewFrame = new FrameWrapper(project);
showPreviewFrame.setTitle(userFile.getName());
LabeledEditor labeledEditor = new LabeledEditor(null);
final EditorFactory factory = EditorFactory.getInstance();
Document document = FileDocumentManager.getInstance().getDocument(userFile);
if (document == null) {
return;
}
final EditorEx createdEditor = (EditorEx) factory.createEditor(document, project, userFile, true);
Disposer.register(project, new Disposable() {
public void dispose() {
factory.releaseEditor(createdEditor);
}
});
for (AnswerPlaceholder answerPlaceholder : taskFile.getActivePlaceholders()) {
if (answerPlaceholder.getActiveSubtaskInfo().isNeedInsertText()) {
answerPlaceholder.setLength(answerPlaceholder.getTaskText().length());
}
Integer minIndex = Collections.min(answerPlaceholder.getSubtaskInfos().keySet());
answerPlaceholder.setUseLength(minIndex >= answerPlaceholder.getActiveSubtaskIndex());
EduAnswerPlaceholderPainter.drawAnswerPlaceholder(createdEditor, answerPlaceholder, JBColor.BLUE);
}
JPanel header = new JPanel();
header.setLayout(new BoxLayout(header, BoxLayout.Y_AXIS));
header.setBorder(new EmptyBorder(10, 10, 10, 10));
header.add(new JLabel("Read-only preview."));
String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
header.add(new JLabel(String.format("Created %s.", timeStamp)));
JComponent editorComponent = createdEditor.getComponent();
labeledEditor.setComponent(editorComponent, header);
createdEditor.setCaretVisible(false);
createdEditor.setCaretEnabled(false);
showPreviewFrame.setComponent(labeledEditor);
showPreviewFrame.setSize(new Dimension(500, 500));
if (!ApplicationManager.getApplication().isUnitTestMode()) {
showPreviewFrame.show();
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class EditorFragmentComponent method showEditorFragmentHint.
@Nullable
public static LightweightHint showEditorFragmentHint(Editor editor, TextRange range, boolean showFolding, boolean hideByAnyKey) {
if (!(editor instanceof EditorEx))
return null;
JRootPane rootPane = editor.getComponent().getRootPane();
if (rootPane == null)
return null;
JLayeredPane layeredPane = rootPane.getLayeredPane();
int lineHeight = editor.getLineHeight();
int overhang = editor.getScrollingModel().getVisibleArea().y - editor.logicalPositionToXY(editor.offsetToLogicalPosition(range.getEndOffset())).y;
int yRelative = overhang > 0 && overhang < lineHeight ? lineHeight - overhang + JBUI.scale(LINE_BORDER_THICKNESS + EMPTY_BORDER_THICKNESS) : 0;
Point point = SwingUtilities.convertPoint(((EditorEx) editor).getScrollPane().getViewport(), -2, yRelative, layeredPane);
return showEditorFragmentHintAt(editor, range, point.y, true, showFolding, hideByAnyKey, true, false);
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class TogglePresentationModeAction method tweakEditorAndFireUpdateUI.
private static void tweakEditorAndFireUpdateUI(UISettings settings, boolean inPresentation) {
EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
int fontSize = inPresentation ? settings.getPresentationModeFontSize() : 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();
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class DiffLineMarkerRenderer method paint.
@Override
public void paint(Editor editor, Graphics g, Rectangle range) {
Color color = myDiffType.getPolygonColor(editor);
if (color == null) {
return;
}
EditorGutterComponentEx gutter = ((EditorEx) editor).getGutterComponentEx();
Graphics2D g2 = (Graphics2D) g;
int x = 0;
int y = range.y;
int width = gutter.getWidth();
int height = range.height;
if (!myDiffType.isApplied()) {
if (height > 2) {
g.setColor(color);
g.fillRect(x, y, width, height);
DiffUtil.drawDoubleShadowedLine(g2, x, x + width, y - 1, color);
DiffUtil.drawDoubleShadowedLine(g2, x, x + width, y + height - 1, color);
} else {
// insertion or deletion, when a range is null. matching the text highlighter which is a 2 pixel line
DiffUtil.drawDoubleShadowedLine(g2, x, x + width, y - 1, color);
}
} else {
DiffUtil.drawBoldDottedFramingLines(g2, x, x + width, y - 1, y + height - 1, color);
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class DiffSideView method applyHighlighter.
private void applyHighlighter() {
EditorEx editor = myEditorSource.getEditor();
if (editor == null)
return;
EditorHighlighter highlighter = myHighlighterFactory.createHighlighter();
if (highlighter != null)
editor.setHighlighter(highlighter);
editor.getSettings().setCaretRowShown(false);
}
Aggregations