Browse Source

Merge pull request #365 in BA/design from ~DANIEL/finereport_design:dev to dev

* commit '9e3fe437e286aebd904a9ec4c8f4d9649bfe8f2e':
  代码
  import
  内存释放问题
  设计器越来越卡的问题
master
superman 8 years ago
parent
commit
8182bf670b
  1. 18
      designer/src/com/fr/design/actions/ElementCaseAction.java
  2. 36
      designer/src/com/fr/design/actions/SelectionListenerAction.java
  3. 56
      designer/src/com/fr/design/actions/cell/GlobalStyleMenuDef.java
  4. 27
      designer_base/src/com/fr/design/actions/UpdateAction.java
  5. 11
      designer_base/src/com/fr/design/menu/MenuDef.java

18
designer/src/com/fr/design/actions/ElementCaseAction.java

@ -10,24 +10,10 @@ import com.fr.grid.selection.Selection;
import com.fr.design.selection.SelectionEvent; import com.fr.design.selection.SelectionEvent;
import com.fr.design.selection.SelectionListener; import com.fr.design.selection.SelectionListener;
public abstract class ElementCaseAction extends TemplateComponentAction<ElementCasePane> { public abstract class ElementCaseAction extends SelectionListenerAction {
protected ElementCaseAction(ElementCasePane t) { protected ElementCaseAction(ElementCasePane t) {
super(t); super(t);
t.addSelectionChangeListener(new SelectionListener() { t.addSelectionChangeListener(createSelectionListener());
@Override
public void selectionChanged(SelectionEvent e) {
update();
if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) {
Selection selection = getEditingComponent().getSelection();
if (selection instanceof CellSelection) {
CellSelection cellselection = (CellSelection) selection;
//样式处理
getEditingComponent().setCellNeedTOFormat(cellselection);
}
}
}
});
} }
} }

36
designer/src/com/fr/design/actions/SelectionListenerAction.java

@ -0,0 +1,36 @@
package com.fr.design.actions;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.ElementCasePane;
import com.fr.design.selection.SelectionEvent;
import com.fr.design.selection.SelectionListener;
import com.fr.grid.selection.CellSelection;
import com.fr.grid.selection.Selection;
/**
* Created by daniel on 2016/10/10.
*/
public abstract class SelectionListenerAction extends TemplateComponentAction<ElementCasePane> {
protected SelectionListenerAction(ElementCasePane elementCasePane) {
super(elementCasePane);
}
protected SelectionListener createSelectionListener () {
return new SelectionListener() {
@Override
public void selectionChanged(SelectionEvent e) {
update();
if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) {
Selection selection = getEditingComponent().getSelection();
if (selection instanceof CellSelection) {
CellSelection cellselection = (CellSelection) selection;
//样式处理
getEditingComponent().setCellNeedTOFormat(cellselection);
}
}
}
};
}
}

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

@ -8,19 +8,27 @@ import com.fr.base.BaseUtils;
import com.fr.base.ConfigManager; import com.fr.base.ConfigManager;
import com.fr.base.NameStyle; import com.fr.base.NameStyle;
import com.fr.design.actions.ElementCaseAction; import com.fr.design.actions.ElementCaseAction;
import com.fr.design.actions.SelectionListenerAction;
import com.fr.design.actions.TemplateComponentAction;
import com.fr.design.actions.UpdateAction; import com.fr.design.actions.UpdateAction;
import com.fr.design.gui.imenu.UIMenu; import com.fr.design.gui.imenu.UIMenu;
import com.fr.design.mainframe.CellElementPropertyPane; import com.fr.design.mainframe.CellElementPropertyPane;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.ElementCasePane;
import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.KeySetUtils;
import com.fr.design.menu.MenuDef; import com.fr.design.menu.MenuDef;
import com.fr.design.selection.SelectionEvent;
import com.fr.design.selection.SelectionListener;
import com.fr.design.style.StylePane; import com.fr.design.style.StylePane;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.base.ConfigManagerProvider; import com.fr.base.ConfigManagerProvider;
import com.fr.grid.selection.CellSelection;
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.*;
import java.util.Iterator; import java.util.Iterator;
public class GlobalStyleMenuDef extends MenuDef { public class GlobalStyleMenuDef extends MenuDef {
@ -35,6 +43,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);
}
}
/** /**
* 更新菜单项 * 更新菜单项
*/ */
@ -46,8 +84,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);
UpdateAction.UseMenuItem useMenuItem =new GlobalStyleSelection(ePane, nameStyle).createUseMenuItem();
UpdateAction.UseMenuItem useMenuItem = new GlobalStyleSelection(ePane, nameStyle).createUseMenuItem();
useMenuItem.setNameStyle(nameStyle); useMenuItem.setNameStyle(nameStyle);
createdMenu.add(useMenuItem); createdMenu.add(useMenuItem);
} }
@ -113,7 +150,9 @@ public class GlobalStyleMenuDef extends MenuDef {
} }
public static class GlobalStyleSelection extends ElementCaseAction {
public static class GlobalStyleSelection extends SelectionListenerAction {
private NameStyle nameStyle; private NameStyle nameStyle;
@ -149,5 +188,14 @@ public class GlobalStyleMenuDef extends MenuDef {
stylePane.updateGlobalStyle(getEditingComponent()); stylePane.updateGlobalStyle(getEditingComponent());
return true; return true;
} }
public UseMenuItem createUseMenuItem() {
UseMenuItem useMenuItem = super.createUseMenuItem();
SelectionListener listener = createSelectionListener();
getEditingComponent().addSelectionChangeListener(listener);
useMenuItem.setSelectionListener(listener);
return 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