Browse Source

REPORT-33690 UIManager中事件监听 没有正确的配对移除 导致内存泄露

feature/big-screen
hades 4 years ago
parent
commit
254e874dc4
  1. 38
      designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java

38
designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java

@ -21,6 +21,8 @@ import com.fr.general.IOUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
@ -82,6 +84,28 @@ public class JSContentPane extends BasicPane {
UIScrollPane sp = new UIScrollPane(contentTextArea);
this.add(sp, BorderLayout.CENTER);
contentTextArea.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
if (ac == null) {
CompletionProvider provider = createCompletionProvider();
ac = new AutoCompletion(provider);
String shortCuts = DesignerEnvManager.getEnvManager().getAutoCompleteShortcuts();
ac.setTriggerKey(convert2KeyStroke(shortCuts));
ac.install(contentTextArea);
}
}
@Override
public void focusLost(FocusEvent e) {
if (ac != null) {
ac.uninstall();
ac = null;
}
}
});
UILabel funNameLabel2 = new UILabel();
funNameLabel2.setText("}");
this.add(funNameLabel2, BorderLayout.SOUTH);
@ -97,24 +121,10 @@ public class JSContentPane extends BasicPane {
}
public void populate(String js) {
if (ac == null) {
CompletionProvider provider = createCompletionProvider();
ac = new AutoCompletion(provider);
String shortCuts = DesignerEnvManager.getEnvManager().getAutoCompleteShortcuts();
ac.setTriggerKey(convert2KeyStroke(shortCuts));
ac.install(contentTextArea);
}
this.contentTextArea.setText(js);
}
public String update() {
if (ac != null) {
this.ac.uninstall();
ac = null;
}
return this.contentTextArea.getText();
}

Loading…
Cancel
Save