Correctly dispose editor instance in AppEditorFontConfigurable

This commit is contained in:
Rustam Vishnyakov
2017-04-20 21:52:07 +03:00
parent b7fa03c1ce
commit 3d66278a25
2 changed files with 45 additions and 12 deletions
@@ -23,6 +23,8 @@ import com.intellij.openapi.editor.colors.impl.AppEditorFontOptions;
import com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.LazyInstance;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -31,7 +33,12 @@ import javax.swing.*;
public class AppEditorFontConfigurable implements SearchableConfigurable {
private AppEditorFontPanel myFontPanel;
private LazyInstance<AppEditorFontPanel> myFontPanelInstance = new LazyInstance<AppEditorFontPanel>() {
@Override
protected Class<AppEditorFontPanel> getInstanceClass() throws ClassNotFoundException {
return AppEditorFontPanel.class;
}
};
@NotNull
@Override
@@ -42,8 +49,7 @@ public class AppEditorFontConfigurable implements SearchableConfigurable {
@Nullable
@Override
public JComponent createComponent() {
myFontPanel = new AppEditorFontPanel();
return myFontPanel;
return getFontPanel().getComponent();
}
@Override
@@ -62,13 +68,13 @@ public class AppEditorFontConfigurable implements SearchableConfigurable {
@NotNull
private FontPreferences getUIFontPreferences() {
return myFontPanel.getOptionsPanel().getFontPreferences();
return getFontPanel().getOptionsPanel().getFontPreferences();
}
@Override
public void reset() {
getStoredPreferences().copyTo(getUIFontPreferences());
myFontPanel.getOptionsPanel().updateOptionsList();
getFontPanel().getOptionsPanel().updateOptionsList();
}
@NotNull
@@ -76,9 +82,21 @@ public class AppEditorFontConfigurable implements SearchableConfigurable {
return AppEditorFontOptions.getInstance().getFontPreferences();
}
@NotNull
private AppEditorFontPanel getFontPanel() {
return myFontPanelInstance.getValue();
}
@Nls
@Override
public String getDisplayName() {
return "Default Font";
}
@Override
public void disposeUIResources() {
if (myFontPanelInstance.isComputed()) {
Disposer.dispose(getFontPanel());
}
}
}
@@ -17,26 +17,29 @@ package com.intellij.application.options.editor.fonts;
import com.intellij.application.options.colors.ColorAndFontSettingsListener;
import com.intellij.application.options.colors.FontEditorPreview;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.impl.FontPreferencesImpl;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
public class AppEditorFontPanel extends JPanel {
public class AppEditorFontPanel implements Disposable {
private final AppEditorFontOptionsPanel myOptionsPanel;
private final FontEditorPreview myPreview;
private final EditorColorsScheme myPreviewScheme;
@NotNull private final AppEditorFontOptionsPanel myOptionsPanel;
@NotNull private final FontEditorPreview myPreview;
@NotNull private final EditorColorsScheme myPreviewScheme;
@NotNull private final JPanel myTopPanel;
public AppEditorFontPanel() {
super(new BorderLayout(0,10));
myTopPanel = new JPanel(new BorderLayout(0,10));
myPreviewScheme = createPreviewScheme();
myOptionsPanel = new AppEditorFontOptionsPanel(myPreviewScheme);
add(myOptionsPanel, BorderLayout.NORTH);
myTopPanel.add(myOptionsPanel, BorderLayout.NORTH);
myPreview = new FontEditorPreview(()-> myPreviewScheme, true);
add(myPreview.getPanel(), BorderLayout.CENTER);
myTopPanel.add(myPreview.getPanel(), BorderLayout.CENTER);
myOptionsPanel.addListener(
new ColorAndFontSettingsListener.Abstract() {
@Override
@@ -47,12 +50,24 @@ public class AppEditorFontPanel extends JPanel {
);
}
@Override
public void dispose() {
myPreview.disposeUIResources();
}
@NotNull
private static EditorColorsScheme createPreviewScheme() {
EditorColorsScheme scheme = (EditorColorsScheme)EditorColorsManager.getInstance().getSchemeForCurrentUITheme().clone();
scheme.setFontPreferences(new FontPreferencesImpl());
return scheme;
}
@NotNull
public JPanel getComponent() {
return myTopPanel;
}
@NotNull
public AppEditorFontOptionsPanel getOptionsPanel() {
return myOptionsPanel;
}