mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EditorImpl: editor-based cell renderer performance & setFontPreferences(): 2
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user