com.intellij.openapi.editor.colors.EditorFontType Java Examples
The following examples show how to use
com.intellij.openapi.editor.colors.EditorFontType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiLineCellRenderer.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
protected Font determineFont(@NotNull String text) { Font finalFont = UIUtil.getFontWithFallback(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN)); FontFallbackIterator it = new FontFallbackIterator(); it.setPreferredFont(finalFont.getFamily(), finalFont.getSize()); it.setFontStyle(finalFont.getStyle()); it.start(text, 0, text.length()); for (; !it.atEnd(); it.advance()) { Font font = it.getFont(); if (!font.getFamily().equals(finalFont.getFamily())) { finalFont = font; break; } } return finalFont; }
Example #2
Source File: LookupCellRenderer.java From consulo with Apache License 2.0 | 6 votes |
public LookupCellRenderer(LookupImpl lookup) { EditorColorsScheme scheme = lookup.getTopLevelEditor().getColorsScheme(); myNormalFont = scheme.getFont(EditorFontType.PLAIN); myBoldFont = scheme.getFont(EditorFontType.BOLD); myLookup = lookup; myNameComponent = new MySimpleColoredComponent(); myNameComponent.setIpad(JBUI.insetsLeft(2)); myNameComponent.setMyBorder(null); myTailComponent = new MySimpleColoredComponent(); myTailComponent.setIpad(JBUI.emptyInsets()); myTailComponent.setBorder(JBUI.Borders.emptyRight(10)); myTypeLabel = new MySimpleColoredComponent(); myTypeLabel.setIpad(JBUI.emptyInsets()); myTypeLabel.setBorder(JBUI.Borders.emptyRight(6)); myPanel = new LookupPanel(); myPanel.add(myNameComponent, BorderLayout.WEST); myPanel.add(myTailComponent, BorderLayout.CENTER); myPanel.add(myTypeLabel, BorderLayout.EAST); myNormalMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myNormalFont); myBoldMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myBoldFont); }
Example #3
Source File: EditorPainter.java From consulo with Apache License 2.0 | 6 votes |
private void paintTextEffect(float xFrom, float xTo, int y, @Nullable Color effectColor, @Nullable EffectType effectType, boolean allowBorder) { if (effectColor == null) { return; } myGraphics.setColor(effectColor); int xStart = (int)xFrom; int xEnd = (int)xTo; if (effectType == EffectType.LINE_UNDERSCORE) { EffectPainter.LINE_UNDERSCORE.paint(myGraphics, xStart, y, xEnd - xStart, myDescent, myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) { EffectPainter.BOLD_LINE_UNDERSCORE.paint(myGraphics, xStart, y, xEnd - xStart, myDescent, myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.STRIKEOUT) { EffectPainter.STRIKE_THROUGH.paint(myGraphics, xStart, y, xEnd - xStart, myView.getCharHeight(), myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.WAVE_UNDERSCORE) { EffectPainter.WAVE_UNDERSCORE.paint(myGraphics, xStart, y, xEnd - xStart, myDescent, myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.BOLD_DOTTED_LINE) { EffectPainter.BOLD_DOTTED_UNDERSCORE.paint(myGraphics, xStart, y, xEnd - xStart, myDescent, myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (allowBorder && (effectType == EffectType.BOXED || effectType == EffectType.ROUNDED_BOX)) { drawSimpleBorder(xFrom, xTo, y - myAscent, effectType == EffectType.ROUNDED_BOX); } }
Example #4
Source File: VariantsCompletionAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull final AnActionEvent e) { final Editor editor = e.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE); if (editor == null) return; final String prefix = myTextField.getText().substring(0, myTextField.getCaretPosition()); if (StringUtil.isEmpty(prefix)) return; final String[] array = calcWords(prefix, editor); if (array.length == 0) { return; } FeatureUsageTracker.getInstance().triggerFeatureUsed("find.completion"); final JList list = new JBList(array) { @Override protected void paintComponent(final Graphics g) { GraphicsUtil.setupAntialiasing(g); super.paintComponent(g); } }; list.setBackground(new JBColor(new Color(235, 244, 254), new Color(0x4C4F51))); list.setFont(editor.getColorsScheme().getFont(EditorFontType.PLAIN)); Utils.showCompletionPopup( e.getInputEvent() instanceof MouseEvent ? myTextField: null, list, null, myTextField, null); }
Example #5
Source File: JBListTable.java From consulo with Apache License 2.0 | 5 votes |
public static JComponent createEditorTextFieldPresentation(final Project project, final FileType type, final String text, boolean selected, boolean focused) { final JPanel panel = new JPanel(new BorderLayout()); final EditorTextField field = new EditorTextField(text, project, type) { @Override protected boolean shouldHaveBorder() { return false; } }; Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); font = new Font(font.getFontName(), font.getStyle(), 12); field.setFont(font); field.addSettingsProvider(EditorSettingsProvider.NO_WHITESPACE); if (selected && focused) { panel.setBackground(UIUtil.getTableSelectionBackground()); field.setAsRendererWithSelection(UIUtil.getTableSelectionBackground(), UIUtil.getTableSelectionForeground()); } else { panel.setBackground(UIUtil.getTableBackground()); if (selected) { panel.setBorder(new DottedBorder(UIUtil.getTableForeground())); } } panel.add(field, BorderLayout.WEST); return panel; }
Example #6
Source File: EditorGutterComponentImpl.java From consulo with Apache License 2.0 | 5 votes |
private void calcAnnotationsSize() { myTextAnnotationGuttersSize = 0; myGapAfterAnnotations = false; final int lineCount = Math.max(myEditor.getDocument().getLineCount(), 1); final int guttersCount = myTextAnnotationGutters.size(); for (int j = 0; j < guttersCount; j++) { TextAnnotationGutterProvider gutterProvider = myTextAnnotationGutters.get(j); int gutterSize = 0; for (int i = 0; i < lineCount; i++) { String lineText = gutterProvider.getLineText(i, myEditor); if (!StringUtil.isEmpty(lineText)) { EditorFontType style = gutterProvider.getStyle(i, myEditor); Font font = getFontForText(lineText, style); FontMetrics fontMetrics = getFontMetrics(font); gutterSize = Math.max(gutterSize, fontMetrics.stringWidth(lineText)); } } if (gutterSize > 0) { boolean margin = gutterProvider.useMargin(); myGapAfterAnnotations = margin; if (margin) { gutterSize += getGapBetweenAnnotations(); } } myTextAnnotationGutterSizes.set(j, gutterSize); myTextAnnotationGuttersSize += gutterSize; } }
Example #7
Source File: MarksCanvas.java From KJump with BSD 3-Clause "New" or "Revised" License | 5 votes |
public final void sync(@NotNull Editor e) { Rectangle visibleArea = e.getScrollingModel().getVisibleArea(); setBounds(visibleArea.x, visibleArea.y, visibleArea.width, visibleArea.height); mEditor = e; mFont = e.getColorsScheme().getFont(EditorFontType.BOLD); mFontMetrics = e.getContentComponent().getFontMetrics(mFont); }
Example #8
Source File: EditorGutterComponentImpl.java From consulo with Apache License 2.0 | 5 votes |
private Font getFontForText(String text, EditorFontType style) { Font font = myEditor.getColorsScheme().getFont(style); if (font.canDisplayUpTo(text) != -1) { font = UIUtil.getFontWithFallback(font); } return font; }
Example #9
Source File: EditorGutterComponentImpl.java From consulo with Apache License 2.0 | 5 votes |
private void paintAnnotationLine(Graphics g, TextAnnotationGutterProvider gutterProvider, int line, int x, int y, int width, int height) { String s = gutterProvider.getLineText(line, myEditor); final Color bg = gutterProvider.getBgColor(line, myEditor); if (bg != null) { g.setColor(bg); g.fillRect(x, y, width, height); } if (!StringUtil.isEmpty(s)) { g.setColor(myEditor.getColorsScheme().getColor(gutterProvider.getColor(line, myEditor))); EditorFontType style = gutterProvider.getStyle(line, myEditor); Font font = getFontForText(s, style); g.setFont(font); g.drawString(s, (gutterProvider.useMargin() ? getGapBetweenAnnotations() / 2 : 0) + x, y + myEditor.getAscent()); } }
Example #10
Source File: ParameterInfoComponent.java From consulo with Apache License 2.0 | 5 votes |
ParameterInfoComponent(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, boolean requestFocus, boolean allowSwitchLabel) { super(new BorderLayout()); myRequestFocus = requestFocus; if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) { JComponent editorComponent = editor.getComponent(); JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane(); myWidthLimit = layeredPane.getWidth(); } NORMAL_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.PLAIN) : UIUtil.getLabelFont(); BOLD_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.BOLD) : NORMAL_FONT.deriveFont(Font.BOLD); myObjects = objects; setBackground(BACKGROUND); myHandler = handler; myMainPanel = new JPanel(new GridBagLayout()); setPanels(); if (myRequestFocus) { AccessibleContextUtil.setName(this, "Parameter Info. Press TAB to navigate through each element. Press ESC to close."); } final JScrollPane pane = ScrollPaneFactory.createScrollPane(myMainPanel, true); add(pane, BorderLayout.CENTER); myAllowSwitchLabel = allowSwitchLabel && !(editor instanceof EditorWindow); setShortcutLabel(); myCurrentParameterIndex = -1; }
Example #11
Source File: EditorPainter.java From consulo with Apache License 2.0 | 5 votes |
private boolean paintPlaceholderText() { CharSequence hintText = myEditor.getPlaceholder(); EditorComponentImpl editorComponent = myEditor.getContentComponent(); if (myDocument.getTextLength() > 0 || hintText == null || hintText.length() == 0 || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == editorComponent && !myEditor.getShowPlaceholderWhenFocused()) { return false; } hintText = SwingUtilities.layoutCompoundLabel(myGraphics.getFontMetrics(), hintText.toString(), null, 0, 0, 0, 0, SwingUtilities.calculateInnerArea(editorComponent, null), // account for insets new Rectangle(), new Rectangle(), 0); EditorFontType fontType = EditorFontType.PLAIN; Color color = myEditor.getFoldingModel().getPlaceholderAttributes().getForegroundColor(); TextAttributes attributes = myEditor.getPlaceholderAttributes(); if (attributes != null) { int type = attributes.getFontType(); if (type == Font.ITALIC) fontType = EditorFontType.ITALIC; else if (type == Font.BOLD) fontType = EditorFontType.BOLD; else if (type == (Font.ITALIC | Font.BOLD)) fontType = EditorFontType.BOLD_ITALIC; Color attColor = attributes.getForegroundColor(); if (attColor != null) color = attColor; } myGraphics.setColor(color); myGraphics.setFont(myEditor.getColorsScheme().getFont(fontType)); myGraphics.drawString(hintText.toString(), myView.getInsets().left, myView.getInsets().top + myAscent + myYShift); return true; }
Example #12
Source File: CSharpChangeSignatureDialog.java From consulo-csharp with Apache License 2.0 | 5 votes |
private int getColumnWidth(int index) { int letters = getTypesMaxLength() + (index == 0 ? 1 : getNamesMaxLength() + 2); Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); font = new Font(font.getFontName(), font.getStyle(), 12); return letters * Toolkit.getDefaultToolkit().getFontMetrics(font).stringWidth("W"); }
Example #13
Source File: ConsolePromptDecorator.java From consulo with Apache License 2.0 | 4 votes |
@Override public EditorFontType getStyle(int line, Editor editor) { return EditorFontType.CONSOLE_PLAIN; }
Example #14
Source File: AnnotateStackTraceAction.java From consulo with Apache License 2.0 | 4 votes |
@Override public EditorFontType getStyle(int line, Editor editor) { LastRevision revision = myRevisions.get(line); return revision != null && revision.getDate().equals(myNewestDate) ? EditorFontType.BOLD : EditorFontType.PLAIN; }
Example #15
Source File: EditorGutterComponentImpl.java From consulo with Apache License 2.0 | 4 votes |
private Font getFontForLineNumbers() { Font editorFont = myEditor.getColorsScheme().getFont(EditorFontType.PLAIN); float editorFontSize = editorFont.getSize2D(); return editorFont.deriveFont(Math.max(1f, editorFontSize - 1f)); }
Example #16
Source File: VcsHistoryUtil.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static Font getCommitDetailsFont() { return JBUI.scale(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN)); }
Example #17
Source File: AnnotationGutterLineConvertorProxy.java From consulo with Apache License 2.0 | 4 votes |
public EditorFontType getStyle(int line, Editor editor) { int currentLine = myGetUpToDateLineNumber.getLineNumber(line); if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return EditorFontType.PLAIN; return myDelegate.getStyle(currentLine, editor); }
Example #18
Source File: AnnotationPresentation.java From consulo with Apache License 2.0 | 4 votes |
@Override public EditorFontType getFontType(final int line) { VcsRevisionNumber revision = myFileAnnotation.originalRevision(line); VcsRevisionNumber currentRevision = myFileAnnotation.getCurrentRevision(); return currentRevision != null && currentRevision.equals(revision) ? EditorFontType.BOLD : EditorFontType.PLAIN; }
Example #19
Source File: AnnotationFieldGutter.java From consulo with Apache License 2.0 | 4 votes |
@Override public EditorFontType getStyle(final int line, final Editor editor) { return myPresentation.getFontType(line); }
Example #20
Source File: EditorGutterComponentImpl.java From consulo with Apache License 2.0 | 4 votes |
private void paintAnnotations(Graphics2D g, int startVisualLine, int endVisualLine) { int x = getAnnotationsAreaOffset(); int w = getAnnotationsAreaWidthEx(); if (w == 0) return; AffineTransform old = setMirrorTransformIfNeeded(g, x, w); try { Color color = myEditor.getColorsScheme().getColor(EditorColors.ANNOTATIONS_COLOR); g.setColor(color != null ? color : JBColor.blue); g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); for (int i = 0; i < myTextAnnotationGutters.size(); i++) { TextAnnotationGutterProvider gutterProvider = myTextAnnotationGutters.get(i); int lineHeight = myEditor.getLineHeight(); int lastLine = myEditor.logicalToVisualPosition(new LogicalPosition(endLineNumber(), 0)).line; endVisualLine = Math.min(endVisualLine, lastLine); if (startVisualLine > endVisualLine) { break; } int annotationSize = myTextAnnotationGutterSizes.get(i); if (startVisualLine == 0 && endVisualLine == 0) { //allow paining gutters for empty documents paintAnnotationLine(g, gutterProvider, 0, x, 0, annotationSize, lineHeight); } else { VisualLinesIterator visLinesIterator = new VisualLinesIterator(myEditor, startVisualLine); while (!visLinesIterator.atEnd() && visLinesIterator.getVisualLine() <= endVisualLine) { int logLine = visLinesIterator.getStartLogicalLine(); int y = visLinesIterator.getY(); paintAnnotationLine(g, gutterProvider, logLine, x, y, annotationSize, lineHeight); visLinesIterator.advance(); } } x += annotationSize; } } finally { if (old != null) g.setTransform(old); } }
Example #21
Source File: EditorView.java From consulo with Apache License 2.0 | 4 votes |
private void initMetricsIfNeeded() { if (myPlainSpaceWidth >= 0) return; Font font = myEditor.getColorsScheme().getFont(EditorFontType.PLAIN); FontMetrics fm = FontInfo.getFontMetrics(font, myFontRenderContext); float width = FontLayoutService.getInstance().charWidth2D(fm, ' '); myPlainSpaceWidth = width > 0 ? width : 1; myCharHeight = FontLayoutService.getInstance().charWidth(fm, 'a'); float verticalScalingFactor = getVerticalScalingFactor(); int fontMetricsHeight = FontLayoutService.getInstance().getHeight(fm); int lineHeight; if (Registry.is("editor.text.xcode.vertical.spacing")) { //Here we approximate line calculation to the variant used in Xcode 9 editor LineMetrics metrics = font.getLineMetrics("", myFontRenderContext); double height = Math.ceil(metrics.getHeight()) + metrics.getLeading(); double delta = verticalScalingFactor - 1; int spacing; if (Math.round((height * delta) / 2) <= 1) { spacing = delta > 0 ? 2 : 0; } else { spacing = ((int)Math.ceil((height * delta) / 2)) * 2; } lineHeight = (int)Math.ceil(height) + spacing; } else if (Registry.is("editor.text.vertical.spacing.correct.rounding")) { if (verticalScalingFactor == 1f) { lineHeight = fontMetricsHeight; } else { Font scaledFont = font.deriveFont(font.getSize() * verticalScalingFactor); FontMetrics scaledMetrics = FontInfo.getFontMetrics(scaledFont, myFontRenderContext); lineHeight = FontLayoutService.getInstance().getHeight(scaledMetrics); } } else { lineHeight = (int)Math.ceil(fontMetricsHeight * verticalScalingFactor); } myLineHeight = Math.max(1, lineHeight); int descent = FontLayoutService.getInstance().getDescent(fm); myDescent = descent + (myLineHeight - fontMetricsHeight) / 2; myTopOverhang = fontMetricsHeight - myLineHeight + myDescent - descent; myBottomOverhang = descent - myDescent; // assuming that bold italic 'W' gives a good approximation of font's widest character FontMetrics fmBI = FontInfo.getFontMetrics(myEditor.getColorsScheme().getFont(EditorFontType.BOLD_ITALIC), myFontRenderContext); myMaxCharWidth = FontLayoutService.getInstance().charWidth2D(fmBI, 'W'); }
Example #22
Source File: Editor.java From consulo with Apache License 2.0 | 4 votes |
/** * Vertical distance, in pixels, between the top of visual line (corresponding coordinate is returned by {@link #visualLineToY(int)}, * {@link #visualPositionToXY(VisualPosition)}, etc) and baseline of text in that visual line. */ default int getAscent() { // actual implementation in EditorImpl is a bit more complex, but this gives an idea how it's constructed return (int)(getContentComponent().getFontMetrics(getColorsScheme().getFont(EditorFontType.PLAIN)).getAscent() * getColorsScheme().getLineSpacing()); }
Example #23
Source File: CsvTableEditor.java From intellij-csv-validator with Apache License 2.0 | 4 votes |
public Font getFont() { return UIUtil.getFontWithFallback(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN)); }
Example #24
Source File: TextAnnotationPresentation.java From consulo with Apache License 2.0 | votes |
EditorFontType getFontType(int line);
Example #25
Source File: TextAnnotationGutterProvider.java From consulo with Apache License 2.0 | votes |
EditorFontType getStyle(int line, Editor editor);