private void update() { if (myMainText == null) { setText(""); } else { setText("<html><head>" + UIUtil.getCssFontDeclaration(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN)) + "</head><body>" + myMainText + "<br/>" + "<br/>" + getBranchesText() + "</body></html>"); } revalidate(); repaint(); }
public int getLineHeight() { synchronized (myLock) { if (myLineHeight < 0) { EditorColorsScheme colorsScheme = myEditor.getColorsScheme(); FontMetrics fm = myEditor.getContentComponent().getFontMetrics(colorsScheme.getFont(EditorFontType.PLAIN)); int fontMetricsHeight = FontLayoutService.getInstance().getHeight(fm); myLineHeight = (int)(fontMetricsHeight * (myEditor.isOneLineMode() ? 1 : colorsScheme.getLineSpacing())); if (myLineHeight <= 0) { myLineHeight = fontMetricsHeight; if (myLineHeight <= 0) { myLineHeight = 12; } } } return myLineHeight; } }
private boolean paintPlaceholderText(Graphics2D g) { 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(g.getFontMetrics(), hintText.toString(), null, 0, 0, 0, 0, editorComponent.getBounds(), new Rectangle(), new Rectangle(), 0); g.setColor(myEditor.getFoldingModel().getPlaceholderAttributes().getForegroundColor()); g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); g.drawString(hintText.toString(), 0, myView.getAscent()); return true; }
private void initMetricsIfNeeded() { if (myPlainSpaceWidth >= 0) return; FontMetrics fm = myEditor.getContentComponent().getFontMetrics(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); int width = FontLayoutService.getInstance().charWidth(fm, ' '); myPlainSpaceWidth = width > 0 ? width : 1; myCharHeight = FontLayoutService.getInstance().charWidth(fm, 'a'); float verticalScalingFactor = getVerticalScalingFactor(); int fontMetricsHeight = FontLayoutService.getInstance().getHeight(fm); myLineHeight = (int)Math.ceil(fontMetricsHeight * verticalScalingFactor); int descent = FontLayoutService.getInstance().getDescent(fm); myDescent = (int)Math.floor(descent * verticalScalingFactor); myTopOverhang = fontMetricsHeight - myLineHeight + myDescent - descent; myBottomOverhang = descent - myDescent; // assuming that bold italic 'W' gives a good approximation of font's widest character FontMetrics fmBI = myEditor.getContentComponent().getFontMetrics(myEditor.getColorsScheme().getFont(EditorFontType.BOLD_ITALIC)); myMaxCharWidth = FontLayoutService.getInstance().charWidth(fmBI, 'W'); }
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); }
public FragmentNumberGutterIconRenderer(String presentation, final TextAttributesKey key, final Component component, EditorEx editor) { myPresentation = presentation; final EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme(); final Color color = globalScheme.getAttributes(key).getBackgroundColor(); myIcon = new CaptionIcon(color, editor.getColorsScheme().getFont(EditorFontType.PLAIN), presentation, component, CaptionIcon.Form.ROUNDED, false, false); }
int getPlainSpaceWidth() { if (myPlainSpaceWidth < 0) { FontMetrics fm = myEditor.getContentComponent().getFontMetrics(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); int width = FontLayoutService.getInstance().charWidth(fm, ' '); myPlainSpaceWidth = width > 0 ? width : 1; } return myPlainSpaceWidth; }
public int getCharHeight() { synchronized (myLock) { if (myCharHeight < 0) { FontMetrics fm = myEditor.getContentComponent().getFontMetrics(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); myCharHeight = FontLayoutService.getInstance().charWidth(fm, 'a'); } return myCharHeight; } }
int getMaxCharWidth() { synchronized (myLock) { if (myMaxCharWidth < 0) { // assuming that bold italic 'W' gives a good approximation of font's widest character FontMetrics fm = myEditor.getContentComponent().getFontMetrics(myEditor.getColorsScheme().getFont(EditorFontType.BOLD_ITALIC)); myMaxCharWidth = FontLayoutService.getInstance().charWidth(fm, 'W'); } return myMaxCharWidth; } }
public int getDescent() { synchronized (myLock) { if (myDescent < 0) { FontMetrics fm = myEditor.getContentComponent().getFontMetrics(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); myDescent = FontLayoutService.getInstance().getDescent(fm); } return myDescent; } }
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; }
public LookupCellRenderer(LookupImpl lookup) { EditorColorsScheme scheme = lookup.getEditor().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(new Insets(0, 0, 0, 0)); myTypeLabel = new MySimpleColoredComponent(); myTypeLabel.setIpad(new Insets(0, 0, 0, 0)); myPanel = new LookupPanel(); myPanel.add(myNameComponent, BorderLayout.WEST); myPanel.add(myTailComponent, BorderLayout.CENTER); myTailComponent.setBorder(new EmptyBorder(0, 0, 0, AFTER_TAIL)); myPanel.add(myTypeLabel, BorderLayout.EAST); myTypeLabel.setBorder(new EmptyBorder(0, 0, 0, AFTER_TYPE)); myNormalMetrics = myLookup.getEditor().getComponent().getFontMetrics(myNormalFont); myBoldMetrics = myLookup.getEditor().getComponent().getFontMetrics(myBoldFont); }
@Override public void actionPerformed(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); }
public MyListCellRenderer() { myPanel = new JPanel(new BorderLayout()); myPanel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); myNameLabel = new JLabel(); myPanel.add(myNameLabel, BorderLayout.WEST); myPanel.add(new JLabel(" ")); myNSLabel = new JLabel(); myPanel.add(myNSLabel, BorderLayout.EAST); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Font font = scheme.getFont(EditorFontType.PLAIN); myNameLabel.setFont(font); myNSLabel.setFont(font); }
private void updateCrumbs() { if (myComponent != null && myEditor != null && !myEditor.isDisposed()) { final Font editorFont = myEditor.getColorsScheme().getFont(EditorFontType.PLAIN); myComponent.setFont(editorFont.deriveFont(Font.PLAIN, editorFont.getSize2D())); updateCrumbs(myEditor.getCaretModel().getLogicalPosition()); } }
public MyListCellRenderer() { myPanel = new JPanel(new BorderLayout()); myPanel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); myNameLabel = new JLabel(); myPanel.add(myNameLabel, BorderLayout.WEST); myPanel.add(new JLabel(" ")); myDescLabel = new JLabel(); myPanel.add(myDescLabel, BorderLayout.EAST); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Font font = scheme.getFont(EditorFontType.PLAIN); myNameLabel.setFont(font); myDescLabel.setFont(font); }
public LookupCellRenderer(LookupImpl lookup) { EditorColorsScheme scheme = lookup.getEditor().getColorsScheme(); myNormalFont = scheme.getFont(EditorFontType.PLAIN); myBoldFont = scheme.getFont(EditorFontType.BOLD); myLookup = lookup; myNameComponent = new MySimpleColoredComponent(); myNameComponent.setIpad(new Insets(0, 0, 0, 0)); myTailComponent = new MySimpleColoredComponent(); myTailComponent.setIpad(new Insets(0, 0, 0, 0)); myTailComponent.setFont(myNormalFont); myTypeLabel = new MySimpleColoredComponent(); myTypeLabel.setIpad(new Insets(0, 0, 0, 0)); myTypeLabel.setFont(myNormalFont); myPanel = new LookupPanel(); myPanel.add(myNameComponent, BorderLayout.WEST); myPanel.add(myTailComponent, BorderLayout.CENTER); myTailComponent.setBorder(new EmptyBorder(0, 0, 0, AFTER_TAIL)); myPanel.add(myTypeLabel, BorderLayout.EAST); myTypeLabel.setBorder(new EmptyBorder(0, 0, 0, AFTER_TYPE)); myNormalMetrics = myLookup.getEditor().getComponent().getFontMetrics(myNormalFont); myBoldMetrics = myLookup.getEditor().getComponent().getFontMetrics(myBoldFont); }
@Override public void actionPerformed(final AnActionEvent e) { final String prefix = getPrefix(); if (StringUtil.isEmpty(prefix)) return; Editor editor = getEditorSearchComponent().getEditor(); if (editor != null) { 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(EditorSearchComponent.COMPLETION_BACKGROUND_COLOR); list.setFont(editor.getColorsScheme().getFont(EditorFontType.PLAIN)); Utils.showCompletionPopup( e.getInputEvent() instanceof MouseEvent ? getEditorSearchComponent().getToolbarComponent() : null, list, null, getTextField(), null); } }
private void updateCrumbs() { if (myComponent != null && myEditor != null) { final Font editorFont = myEditor.getColorsScheme().getFont(EditorFontType.PLAIN); myComponent.setFont(editorFont.deriveFont(Font.PLAIN, editorFont.getSize2D())); updateCrumbs(myEditor.getCaretModel().getLogicalPosition()); } }
public JComponent createOptionsPanel() { myCopyrightPane.setFont(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN)); myValidateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { VelocityHelper.verify(myCopyrightPane.getText()); Messages.showInfoMessage(myProject, "Velocity template is valid.", "Validation"); } catch (Exception e1) { Messages.showInfoMessage(myProject, "Velocity template contains error:\n" + e1.getMessage(), "Validation"); } } }); return myWholePanel; }
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"); }
@Override public EditorFontType getStyle(int line, Editor editor) { VcsRevisionNumber revisionNumber = annotation.getLineRevisionNumber(line); if (revisionNumber != null && revisionNumber.equals(annotation.getCurrentRevision())) { return EditorFontType.BOLD_ITALIC; } else { return EditorFontType.ITALIC; } }
private boolean paintPlaceholderText(Graphics2D g) { 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(g.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; } g.setColor(color); g.setFont(myEditor.getColorsScheme().getFont(fontType)); Insets insets = myView.getInsets(); g.drawString(hintText.toString(), insets.left, insets.top + myView.getAscent()); return true; }
private void paintTextEffect(Graphics2D g, float xFrom, float xTo, int y, Color effectColor, EffectType effectType, boolean allowBorder) { g.setColor(effectColor); int xStart = (int)xFrom; int xEnd = (int)xTo; if (effectType == EffectType.LINE_UNDERSCORE) { EffectPainter.LINE_UNDERSCORE.paint(g, xStart, y, xEnd - xStart, myView.getDescent(), myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) { EffectPainter.BOLD_LINE_UNDERSCORE.paint(g, xStart, y, xEnd - xStart, myView.getDescent(), myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.STRIKEOUT) { EffectPainter.STRIKE_THROUGH.paint(g, xStart, y, xEnd - xStart, myView.getCharHeight(), myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.WAVE_UNDERSCORE) { EffectPainter.WAVE_UNDERSCORE.paint(g, xStart, y, xEnd - xStart, myView.getDescent(), myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (effectType == EffectType.BOLD_DOTTED_LINE) { EffectPainter.BOLD_DOTTED_UNDERSCORE.paint(g, xStart, y, xEnd - xStart, myView.getDescent(), myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); } else if (allowBorder && (effectType == EffectType.BOXED || effectType == EffectType.ROUNDED_BOX)) { drawSimpleBorder(g, xFrom, xTo, y - myView.getAscent(), effectType == EffectType.ROUNDED_BOX); } }
@RequiredDispatchThread @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); }
@NotNull public static String getRightArrow() { Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); return FontUtil.rightArrow(font); }
@Override public void setFont(EditorFontType key, Font font) { }
public void resetFont(final Editor editor) { myIcon.setFont(editor.getColorsScheme().getFont(EditorFontType.PLAIN)); }
private void paintAnnotations(Graphics2D g, Rectangle clip) { int x = getAnnotationsAreaOffset(); int w = getAnnotationsAreaWidthEx(); if (w == 0) return; AffineTransform old = g.getTransform(); g.setTransform(getMirrorTransform(old, 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 startLineNumber = clip.y / lineHeight; int endLineNumber = (clip.y + clip.height) / lineHeight + 1; int lastLine = myEditor.logicalToVisualPosition( new LogicalPosition(endLineNumber(), 0)) .line; endLineNumber = Math.min(endLineNumber, lastLine + 1); if (startLineNumber >= endLineNumber) { break; } int annotationSize = myTextAnnotationGutterSizes.get(i); for (int j = startLineNumber; j < endLineNumber; j++) { int logLine = myEditor.visualToLogicalPosition(new VisualPosition(j, 0)).line; String s = gutterProvider.getLineText(logLine, myEditor); final EditorFontType style = gutterProvider.getStyle(logLine, myEditor); final Color bg = gutterProvider.getBgColor(logLine, myEditor); if (bg != null) { g.setColor(bg); g.fillRect(x, j * lineHeight, annotationSize, lineHeight); } g.setColor(myEditor.getColorsScheme().getColor(gutterProvider.getColor(logLine, myEditor))); g.setFont(myEditor.getColorsScheme().getFont(style)); if (s != null) { g.drawString(s, x, (j + 1) * lineHeight - myEditor.getDescent()); } } x += annotationSize; } } finally { g.setTransform(old); } }
private void doPaintLineNumbers(Graphics2D g, Rectangle clip, int offset, @NotNull TIntFunction convertor) { if (!isLineNumbersShown()) { return; } int lineHeight = myEditor.getLineHeight(); int startLineNumber = clip.y / lineHeight; int endLineNumber = (clip.y + clip.height) / lineHeight + 1; int lastLine = myEditor.logicalToVisualPosition( new LogicalPosition(endLineNumber(), 0)) .line; endLineNumber = Math.min(endLineNumber, lastLine + 1); if (startLineNumber >= endLineNumber) { return; } Color color = myEditor.getColorsScheme().getColor(EditorColors.LINE_NUMBERS_COLOR); g.setColor(color != null ? color : JBColor.blue); g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); AffineTransform old = g.getTransform(); g.setTransform(getMirrorTransform(old, getLineNumberAreaOffset(), getLineNumberAreaWidth())); try { for (int i = startLineNumber; i < endLineNumber; i++) { LogicalPosition logicalPosition = myEditor.visualToLogicalPosition(new VisualPosition(i, 0)); if (EditorUtil.getSoftWrapCountAfterLineStart(myEditor, logicalPosition) > 0) { continue; } int logLine = convertor.execute(logicalPosition.line); if (logLine >= 0) { String s = String.valueOf(logLine + 1); int startY = (i + 1) * lineHeight; if (myEditor.isInDistractionFreeMode()) { Color fgColor = myTextFgColors.get(i); g.setColor(fgColor != null ? fgColor : color != null ? color : JBColor.blue); } int textOffset = isMirrored() ? offset - getLineNumberAreaWidth() - 1: offset - myEditor.getFontMetrics(Font.PLAIN).stringWidth(s); g.drawString(s, textOffset, startY - myEditor.getDescent()); } } } finally { g.setTransform(old); } }
public EditorFontType getStyle(final int line, final Editor editor) { return myPresentation.getFontType(line); }
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; }