Browse Source

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

Merge in DESIGN/design from ~HADES/design:release/10.0 to release/10.0

* commit 'f5a89c3de8635d6564d462ab21682c38296bef79':
  REPORT-33690 抽出方法
  REPORT-33690 UIManager中事件监听 没有正确的配对移除 导致内存泄露
feature/big-screen
Hades 4 years ago
parent
commit
e7a8c232a8
  1. 46
      designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java

46
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,20 @@ 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) {
// 获得焦点时 安装
installAutoCompletion();
}
@Override
public void focusLost(FocusEvent e) {
// 失去焦点时 卸载
uninstallAutoCompletion();
}
});
UILabel funNameLabel2 = new UILabel();
funNameLabel2.setText("}");
this.add(funNameLabel2, BorderLayout.SOUTH);
@ -91,12 +107,10 @@ public class JSContentPane extends BasicPane {
return KeyStroke.getKeyStroke(ks.replace("+", "pressed"));
}
@Override
protected String title4PopupWindow() {
return "JS";
}
public void populate(String js) {
/**
* 注册安装 自动补全监听
*/
private void installAutoCompletion() {
if (ac == null) {
CompletionProvider provider = createCompletionProvider();
ac = new AutoCompletion(provider);
@ -105,16 +119,28 @@ public class JSContentPane extends BasicPane {
ac.setTriggerKey(convert2KeyStroke(shortCuts));
ac.install(contentTextArea);
}
this.contentTextArea.setText(js);
}
public String update() {
/**
* 卸载移除 自动补全监听
*/
private void uninstallAutoCompletion() {
if (ac != null) {
this.ac.uninstall();
ac.uninstall();
ac = null;
}
}
@Override
protected String title4PopupWindow() {
return "JS";
}
public void populate(String js) {
this.contentTextArea.setText(js);
}
public String update() {
return this.contentTextArea.getText();
}

Loading…
Cancel
Save