From 3f3f8a1c3fafb2565a8f63fe1cda44c10e9ab2b9 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Tue, 18 Nov 2014 20:15:58 +0300 Subject: [PATCH] EditorImpl: editor-based cell renderer performance & setFontPreferences(): 2 --- .../openapi/editor/impl/EditorImpl.java | 40 ++++++++++--------- .../ui/EditorTextFieldCellRenderer.java | 31 +++++++------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 5d12c0e10a42..231d9fb8bec2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -2278,8 +2278,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi @NotNull VisualPosition clipStartVisualPos, int clipStartOffset, int clipEndOffset) { Color defaultBackground = getBackgroundColor(); - g.setColor(defaultBackground); - g.fillRect(clip.x, clip.y, clip.width, clip.height); + if (myEditorComponent.isOpaque()) { + g.setColor(defaultBackground); + g.fillRect(clip.x, clip.y, clip.width, clip.height); + } int lineHeight = getLineHeight(); @@ -4630,7 +4632,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } private void paint(@NotNull Graphics g) { - if (!isEnabled() || !myIsShown || !IJSwingUtilities.hasFocus(getContentComponent()) || isRendererMode()) return; + if (!isEnabled() || !myIsShown || isRendererMode() || !IJSwingUtilities.hasFocus(getContentComponent())) return; if (myCaretModel.supportsMultipleCarets()) { for (CaretRectangle location : myLocations) { @@ -6058,11 +6060,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi updateGlobalScheme(); } - private EditorColorsScheme getGlobal() { - return getDelegate(); - } - - protected void initFonts() { + private void reinitFonts() { String editorFontName = getEditorFontName(); int editorFontSize = getEditorFontSize(); @@ -6080,14 +6078,17 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi myFontsMap.put(EditorFontType.BOLD, boldFont); myFontsMap.put(EditorFontType.ITALIC, italicFont); myFontsMap.put(EditorFontType.BOLD_ITALIC, boldItalicFont); + } + protected void reinitFontsAndSettings() { + reinitFonts(); reinitSettings(); } @Override public TextAttributes getAttributes(TextAttributesKey key) { if (myOwnAttributes.containsKey(key)) return myOwnAttributes.get(key); - return getGlobal().getAttributes(key); + return getDelegate().getAttributes(key); } @Override @@ -6098,7 +6099,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi @Override public Color getColor(ColorKey key) { if (myOwnColors.containsKey(key)) return myOwnColors.get(key); - return getGlobal().getColor(key); + return getDelegate().getColor(key); } @Override @@ -6114,7 +6115,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi @Override public int getEditorFontSize() { if (myFontSize == -1) { - return getGlobal().getEditorFontSize(); + return getDelegate().getEditorFontSize(); } return myFontSize; } @@ -6125,13 +6126,13 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi if (fontSize > myMaxFontSize) fontSize = myMaxFontSize; if (fontSize == myFontSize) return; myFontSize = fontSize; - initFonts(); + reinitFontsAndSettings(); } @NotNull @Override public FontPreferences getFontPreferences() { - return myFontPreferences.getEffectiveFontFamilies().isEmpty() ? getGlobal().getFontPreferences() : myFontPreferences; + return myFontPreferences.getEffectiveFontFamilies().isEmpty() ? getDelegate().getFontPreferences() : myFontPreferences; } @Override @@ -6144,7 +6145,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi @Override public String getEditorFontName() { if (myFaceName == null) { - return getGlobal().getEditorFontName(); + return getDelegate().getEditorFontName(); } return myFaceName; } @@ -6153,7 +6154,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi public void setEditorFontName(String fontName) { if (Comparing.equal(fontName, myFaceName)) return; myFaceName = fontName; - initFonts(); + reinitFontsAndSettings(); } @Override @@ -6162,13 +6163,13 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi Font font = myFontsMap.get(key); if (font != null) return font; } - return getGlobal().getFont(key); + return getDelegate().getFont(key); } @Override public void setFont(EditorFontType key, Font font) { if (myFontsMap == null) { - initFonts(); + reinitFontsAndSettings(); } myFontsMap.put(key, font); reinitSettings(); @@ -6187,13 +6188,14 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi @Override public void setDelegate(@NotNull EditorColorsScheme delegate) { super.setDelegate(delegate); - int globalFontSize = getGlobal().getEditorFontSize(); + int globalFontSize = getDelegate().getEditorFontSize(); myMaxFontSize = Math.max(OptionsConstants.MAX_EDITOR_FONT_SIZE, globalFontSize); + reinitFonts(); } @Override public void setConsoleFontSize(int fontSize) { - getGlobal().setConsoleFontSize(fontSize); + getDelegate().setConsoleFontSize(fontSize); reinitSettings(); } } diff --git a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java index ed7d1311beb7..d48e8c5654d9 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java @@ -31,10 +31,7 @@ import com.intellij.openapi.editor.markup.HighlighterLayer; import com.intellij.openapi.editor.markup.HighlighterTargetArea; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileTypes.FileTypes; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; @@ -74,7 +71,7 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { MyPanel panel = getEditorPanel(table); EditorEx editor = panel.myEditor; - updateFonts(editor.getColorsScheme(), getColorScheme(), table.getFont().getSize()); + editor.getColorsScheme().setEditorFontSize(table.getFont().getSize()); String text = getText(((EditorImpl)editor).getFontMetrics(Font.PLAIN), table, value, row, column); TextAttributes textAttributes = getTextAttributes(value, isSelected, row, column); panel.setText(text, textAttributes); @@ -84,19 +81,13 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, editor.getColorsScheme().setColor(EditorColors.SELECTION_BACKGROUND_COLOR, table.getSelectionBackground()); editor.getColorsScheme().setColor(EditorColors.SELECTION_FOREGROUND_COLOR, table.getSelectionForeground()); editor.setBackgroundColor(getCellBackgroundColor(getColorScheme(), table, isSelected, row)); + panel.setOpaque(!Comparing.equal(editor.getBackgroundColor(), table.getBackground())); panel.setBorder(null); // prevents double border painting when ExtendedItemRendererComponentWrapper is used return panel; } - private static void updateFonts(EditorColorsScheme target, EditorColorsScheme source, int fontSize) { - target.setEditorFontName(source.getEditorFontName()); - target.setEditorFontSize(fontSize); - target.setLineSpacing(source.getLineSpacing()); - target.setFontPreferences(source.getFontPreferences()); - } - public static Color getCellBackgroundColor(EditorColorsScheme colorsScheme, JTable table, boolean isSelected, int row) { return isSelected ? table.getSelectionBackground() : table.getSelectionModel().getLeadSelectionIndex() == row ? colorsScheme.getColor(EditorColors.CARET_ROW_COLOR) : @@ -107,10 +98,8 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, private MyPanel getEditorPanel(JTable table) { MyPanel panel = UIUtil.getClientProperty(table, MY_PANEL_PROPERTY); if (panel != null) { - EditorColorsScheme scheme = panel.myEditor.getColorsScheme(); - if (scheme instanceof DelegateColorScheme) { - ((DelegateColorScheme)scheme).setDelegate(getColorScheme()); - } + DelegateColorScheme scheme = (DelegateColorScheme)panel.myEditor.getColorsScheme(); + scheme.setDelegate(getColorScheme()); return panel; } @@ -154,6 +143,13 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, this.myEditor = editor; } + @Override + public void setOpaque(boolean isOpaque) { + if (myEditor != null) { + myEditor.getContentComponent().setOpaque(isOpaque); + } + } + public void setText(String text, @Nullable TextAttributes textAttributes) { myRawText = text; myTextAttributes = textAttributes; @@ -167,7 +163,8 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, @Override protected void paintComponent(Graphics g) { - if (getBorder() == null) return; + if (getBorder() == null || !myEditor.getContentComponent().isOpaque()) return; + Color oldColor = g.getColor(); g.setColor(myEditor.getBackgroundColor()); Insets insets = getInsets();