Browse Source

内存释放问题

master
daniel 8 years ago
parent
commit
a7ea035308
  1. 60
      designer/src/com/fr/design/actions/cell/GlobalStyleMenuDef.java
  2. 4
      designer/src/com/fr/grid/selection/CellSelection.java
  3. 27
      designer_base/src/com/fr/design/actions/UpdateAction.java
  4. 11
      designer_base/src/com/fr/design/menu/MenuDef.java

60
designer/src/com/fr/design/actions/cell/GlobalStyleMenuDef.java

@ -26,9 +26,8 @@ import com.fr.grid.selection.Selection;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.pinyin.PinyinHelper; import com.fr.stable.pinyin.PinyinHelper;
import java.awt.event.ActionEvent; import java.awt.*;
import java.awt.event.HierarchyEvent; import java.awt.event.*;
import java.awt.event.HierarchyListener;
import java.util.Iterator; import java.util.Iterator;
public class GlobalStyleMenuDef extends MenuDef { public class GlobalStyleMenuDef extends MenuDef {
@ -43,6 +42,36 @@ public class GlobalStyleMenuDef extends MenuDef {
this.setIconPath("/com/fr/design/images/m_web/style.png"); this.setIconPath("/com/fr/design/images/m_web/style.png");
} }
protected ContainerListener getContainerListener() {
return containerListener;
}
private ContainerListener containerListener = new ContainerListener() {
@Override
public void componentAdded(ContainerEvent e) {
}
@Override
public void componentRemoved(ContainerEvent e) {
Component c = e.getChild();
c.dispatchEvent(new MenuDeleteEvent(c));
}
};
private class MenuDeleteEvent extends UpdateAction.ComponentRemoveEvent {
public MenuDeleteEvent(Component source) {
super(source);
}
@Override
public void release(SelectionListener listener) {
ePane.removeSelectionChangeListener(listener);
}
}
/** /**
* 更新菜单项 * 更新菜单项
*/ */
@ -54,9 +83,7 @@ public class GlobalStyleMenuDef extends MenuDef {
while (iterator.hasNext()) { while (iterator.hasNext()) {
String name = (String) iterator.next(); String name = (String) iterator.next();
NameStyle nameStyle = NameStyle.getInstance(name); NameStyle nameStyle = NameStyle.getInstance(name);
GlobalStyleSelection selection = new GlobalStyleSelection(ePane, nameStyle); UpdateAction.UseMenuItem useMenuItem =new GlobalStyleSelection(ePane, nameStyle).createUseMenuItem();
UpdateAction.UseMenuItem useMenuItem =selection.createUseMenuItem();
selection.registerSelectionListener(ePane, useMenuItem);
useMenuItem.setNameStyle(nameStyle); useMenuItem.setNameStyle(nameStyle);
createdMenu.add(useMenuItem); createdMenu.add(useMenuItem);
} }
@ -161,6 +188,14 @@ public class GlobalStyleMenuDef extends MenuDef {
return true; return true;
} }
public UseMenuItem createUseMenuItem() {
UseMenuItem useMenuItem = super.createUseMenuItem();
SelectionListener listener = createSelectionListener();
getEditingComponent().addSelectionChangeListener(listener);
useMenuItem.setSelectionListener(listener);
return useMenuItem;
}
private SelectionListener createSelectionListener (){ private SelectionListener createSelectionListener (){
return new SelectionListener (){ return new SelectionListener (){
@ -178,18 +213,5 @@ public class GlobalStyleMenuDef extends MenuDef {
} }
}; };
} }
public void registerSelectionListener(final ElementCasePane ePane, UseMenuItem useMenuItem) {
SelectionListener listener = createSelectionListener();
ePane.addSelectionChangeListener(listener);
useMenuItem.addHierarchyListener(new HierarchyListener(){
@Override
public void hierarchyChanged(HierarchyEvent e) {
ePane.removeSelectionChangeListener(listener);
}
});
}
} }
} }

4
designer/src/com/fr/grid/selection/CellSelection.java

@ -437,9 +437,7 @@ public class CellSelection extends Selection {
String name = (String) iterato.next(); String name = (String) iterato.next();
name = GlobalStyleMenuDef.judgeChina(name); name = GlobalStyleMenuDef.judgeChina(name);
NameStyle nameStyle = NameStyle.getInstance(name); NameStyle nameStyle = NameStyle.getInstance(name);
GlobalStyleSelection selection = new GlobalStyleSelection(ePane, nameStyle); UpdateAction.UseMenuItem useMenuItem = new GlobalStyleSelection(ePane, nameStyle).createUseMenuItem();
UpdateAction.UseMenuItem useMenuItem = selection.createUseMenuItem();
selection.registerSelectionListener(ePane, useMenuItem);
useMenuItem.setNameStyle(nameStyle); useMenuItem.setNameStyle(nameStyle);
styleMenu.add(useMenuItem); styleMenu.add(useMenuItem);
} }

27
designer_base/src/com/fr/design/actions/UpdateAction.java

@ -12,10 +12,13 @@ import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.imenu.UICheckBoxMenuItem; import com.fr.design.gui.imenu.UICheckBoxMenuItem;
import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
import com.fr.design.selection.SelectionListener;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ContainerEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -321,12 +324,24 @@ public abstract class UpdateAction extends ShortCut implements Action {
toolBar.add(this.createToolBarComponent()); toolBar.add(this.createToolBarComponent());
} }
public abstract static class ComponentRemoveEvent extends ComponentEvent {
private static int EVENT_DELETE= 3001;
public ComponentRemoveEvent(Component source) {
super(source, EVENT_DELETE);
}
public abstract void release(SelectionListener listener);
}
/** /**
* 全局style的菜单 * 全局style的菜单
*/ */
public static class UseMenuItem extends UIMenuItem { public static class UseMenuItem extends UIMenuItem {
private NameStyle nameStyle; private NameStyle nameStyle;
private SelectionListener listener;
public UseMenuItem(Action action) { public UseMenuItem(Action action) {
super(action); super(action);
@ -337,6 +352,18 @@ public abstract class UpdateAction extends ShortCut implements Action {
super(text, icon); super(text, icon);
} }
protected void processEvent(AWTEvent e) {
if (e instanceof ComponentRemoveEvent) {
((ComponentRemoveEvent) e).release(listener);
return;
}
super.processEvent(e);
}
public void setSelectionListener(SelectionListener listener) {
this.listener = listener;
}
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);

11
designer_base/src/com/fr/design/menu/MenuDef.java

@ -13,9 +13,7 @@ import javax.swing.*;
import javax.swing.event.MenuEvent; import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener; import javax.swing.event.MenuListener;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseAdapter; import java.awt.event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -164,11 +162,18 @@ public class MenuDef extends ShortCut {
createdJMenu.setIcon(BaseUtils.readIcon(this.iconPath)); createdJMenu.setIcon(BaseUtils.readIcon(this.iconPath));
} }
createdJMenu.addMenuListener(menuDefListener); createdJMenu.addMenuListener(menuDefListener);
ContainerListener listener = getContainerListener();
if(listener != null){
createdJMenu.getPopupMenu().addContainerListener(listener);
}
} }
return createdJMenu; return createdJMenu;
} }
protected ContainerListener getContainerListener() {
return null;
}
/** /**
* 生成 JPopupMenu * 生成 JPopupMenu
* @return 弹出菜单 * @return 弹出菜单

Loading…
Cancel
Save