Browse Source

REPORT-5033 设计器打开模板内存优化.

master
MoMeak 7 years ago
parent
commit
16b158d127
  1. 5
      designer/src/com/fr/design/mainframe/JWorkBook.java
  2. 2
      designer_base/src/com/fr/design/designer/TargetComponent.java
  3. 43
      designer_base/src/com/fr/design/file/HistoryTemplateListPane.java
  4. 22
      designer_base/src/com/fr/design/file/MutilTempalteTabPane.java
  5. 8
      designer_base/src/com/fr/design/mainframe/DesignerFrame.java
  6. 9
      designer_base/src/com/fr/design/mainframe/JTemplate.java
  7. 253
      designer_base/src/com/fr/design/mainframe/JVirtualTemplate.java
  8. 5
      designer_form/src/com/fr/design/mainframe/JForm.java

5
designer/src/com/fr/design/mainframe/JWorkBook.java

@ -849,6 +849,11 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
return true;
}
@Override
public boolean isJVirtualTemplate() {
return false;
}
@Override
public HyperlinkGroupPane getHyperLinkPane(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) {
return ReportHyperlinkGroupPane.getInstance(hyperlinkGroupPaneActionProvider);

2
designer_base/src/com/fr/design/designer/TargetComponent.java

@ -22,6 +22,8 @@ public abstract class TargetComponent<T> extends JComponent {
this.target = t;
}
public TargetComponent() {}
// TODO ALEX_SEP JWorkBook不想有copy, paste, cut的操作,怎么办?
public abstract void copy();

43
designer_base/src/com/fr/design/file/HistoryTemplateListPane.java

@ -25,6 +25,7 @@ import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilist.UIList;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.JVirtualTemplate;
import com.fr.design.module.DesignModuleFactory;
import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
@ -36,6 +37,8 @@ import com.fr.stable.project.ProjectConstants;
import com.fr.design.utils.gui.GUIPaintUtils;
public class HistoryTemplateListPane extends JPanel implements FileOperations {
//最大保存内存中面板数,为0时关闭优化内存
private static final int DEAD_LINE = 5;
private static final int LIST_BORDER = 4;
private List<JTemplate<?, ?>> historyList;
private JTemplate<?, ?> editingTemplate;
@ -124,6 +127,26 @@ public class HistoryTemplateListPane extends JPanel implements FileOperations {
}
/**
* 临时关闭选择的文件
* @param selected 选择的
*/
public void closeVirtualSelectedReport(JTemplate<?, ?> selected) {
DesignModuleFactory.clearChartPropertyPane();
DesignTableDataManager.closeTemplate(selected);
GeneralContext.removeEnvWillChangedListener(selected.getFullPathName());
if (contains(selected) == -1) {
return;
}
selected.fireJTemplateClosed();
selected.stopEditing();
try {
selected.getEditingFILE().closeTemplate();
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
public JTemplate<?, ?> getCurrentEditingTemplate() {
return this.editingTemplate;
}
@ -281,10 +304,30 @@ public class HistoryTemplateListPane extends JPanel implements FileOperations {
public void add(JTemplate<?, ?> jt) {
historyList.add(jt);
closeOverLineTemplate();
refresh();
}
}
/**
* 打开new模板的同时关闭old模板,优先关已保存的先打开的
*/
public void closeOverLineTemplate() {
int size = historyList.size();
int vCount = size - DEAD_LINE;
if (DEAD_LINE == 0 || vCount <= 0) {
return;
}
for (int i = 0; i < vCount; i++) {
JTemplate overTemplate = historyList.get(i);
if (!overTemplate.isJVirtualTemplate() && overTemplate.getEditingFILE().exists() && overTemplate.isALLSaved() && overTemplate != editingTemplate) {
closeVirtualSelectedReport(overTemplate);
historyList.set(i, new JVirtualTemplate(overTemplate.getEditingFILE()));
}
}
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
}
/**
* 刷新
*/

22
designer_base/src/com/fr/design/file/MutilTempalteTabPane.java

@ -219,12 +219,14 @@ public class MutilTempalteTabPane extends JComponent implements MouseListener, M
templates[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectedIndex = index;
DesignerContext.getDesignerFrame().addAndActivateJTemplate(tem);
if (!tem.isJVirtualTemplate()) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate(tem);
} else {
DesignerContext.getDesignerFrame().openTemplate(tem.getEditingFILE());
}
}
});
}
return templates;
}
@ -672,7 +674,12 @@ public class MutilTempalteTabPane extends JComponent implements MouseListener, M
this.repaint();
return;
}
DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(getTemplateIndex(evtX)));
JTemplate evtXTemplate = openedTemplate.get(getTemplateIndex(evtX));
if (!evtXTemplate.isJVirtualTemplate()) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(getTemplateIndex(evtX)));
} else {
DesignerContext.getDesignerFrame().openTemplate(evtXTemplate.getEditingFILE());
}
}
isShowList = false;
}
@ -779,7 +786,12 @@ public class MutilTempalteTabPane extends JComponent implements MouseListener, M
//如果关闭的模板不是当前选中的模板,则激活的模板不变
selectedIndex = HistoryTemplateListPane.getInstance().contains(fileName);
}
DesignerContext.getDesignerFrame().activateJTemplate(openedTemplate.get(selectedIndex));
//如果是已后台关闭的模板,则重新打开文件
if (!openedTemplate.get(selectedIndex).isJVirtualTemplate()) {
DesignerContext.getDesignerFrame().activateJTemplate(openedTemplate.get(selectedIndex));
} else {
DesignerContext.getDesignerFrame().openTemplate(openedTemplate.get(selectedIndex).getEditingFILE());
}
}
}

8
designer_base/src/com/fr/design/mainframe/DesignerFrame.java

@ -933,8 +933,14 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
}
fullName = fullName.replaceAll("/", "\\\\");
int index = HistoryTemplateListPane.getInstance().contains(fullName);
List<JTemplate<?, ?>> historyList = HistoryTemplateListPane.getInstance().getHistoryList();
if (index != -1) {
this.activateJTemplate(HistoryTemplateListPane.getInstance().getHistoryList().get(index));
if (!historyList.get(index).isJVirtualTemplate()) {
this.activateJTemplate(historyList.get(index));
} else {
historyList.set(index, jt);
this.addAndActivateJTemplate(historyList.get(index));
}
} else {
this.addAndActivateJTemplate(jt);
}

9
designer_base/src/com/fr/design/mainframe/JTemplate.java

@ -83,6 +83,8 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
private StringBuilder process = new StringBuilder(""); // 制作模板的过程
public int resolution = ScreenResolution.getScreenResolution();
public JTemplate() {}
public JTemplate(T t, String defaultFileName) {
this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true);
openTime = System.currentTimeMillis();
@ -884,6 +886,13 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
*/
public abstract boolean isJWorkBook();
/**
* 是否是虚拟工作薄用于释放该template内存
*
* @return 是则返回true
*/
public abstract boolean isJVirtualTemplate();
/**
* 返回当前支持的超链界面pane
* @return 超链连接界面

253
designer_base/src/com/fr/design/mainframe/JVirtualTemplate.java

@ -0,0 +1,253 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.DesignModelAdapter;
import com.fr.design.designer.TargetComponent;
import com.fr.design.gui.frpane.HyperlinkGroupPane;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.mainframe.templateinfo.TemplateProcessInfo;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef;
import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
import com.fr.stable.project.ProjectConstants;
import javax.swing.*;
import java.io.File;
/**
* Author : MoMeak
* Date: 17-11-20
* 极简模式模板----for减少堆内存引用
* 其他参数都去掉只保留触发重新激活的文件路径
*/
public class JVirtualTemplate extends JTemplate {
private FILE editingFILE = null;
public JVirtualTemplate(FILE editingFILE) {
setEditingFILE(editingFILE);
}
public String getFullPathName() {
String editingFileName = getEditingFILE().getPath();
if (editingFileName.startsWith(ProjectConstants.REPORTLETS_NAME)) {
editingFileName = ((FileNodeFILE) getEditingFILE()).getEnvPath() + File.separator + editingFileName;
}
return editingFileName.replaceAll("/", "\\\\");
}
/**
* 得到正在编辑的FILE
*
* @return
*/
public FILE getEditingFILE() {
return this.editingFILE;
}
/**
* 正在编辑的FILE
*
* @return
*/
public void setEditingFILE(FILE editingFILE) {
this.editingFILE = editingFILE;
}
@Override
public void refreshEastPropertiesPane() {
}
@Override
public TargetComponent getCurrentElementCasePane() {
return null;
}
@Override
public JComponent getCurrentReportComponentPane() {
return null;
}
@Override
public TemplateProcessInfo getProcessInfo() {
return null;
}
@Override
public void setJTemplateResolution(int resolution) {
}
@Override
public int getJTemplateResolution() {
return 0;
}
@Override
protected JComponent createCenterPane() {
return null;
}
@Override
public void removeTemplateSelection() {
}
@Override
public void refreshContainer() {
}
@Override
public void removeParameterPaneSelection() {
}
@Override
public void setScale(int resolution) {
}
@Override
public int getScale() {
return 0;
}
@Override
public int selfAdaptUpdate() {
return 0;
}
@Override
protected DesignModelAdapter createDesignModel() {
return null;
}
@Override
public UIMenuItem[] createMenuItem4Preview() {
return new UIMenuItem[0];
}
@Override
protected BaseUndoState<?> createUndoState() {
return null;
}
@Override
public String suffix() {
return null;
}
@Override
public void copy() {
}
@Override
public boolean paste() {
return false;
}
@Override
public boolean cut() {
return false;
}
@Override
public AuthorityEditPane createAuthorityEditPane() {
return null;
}
@Override
public ToolBarMenuDockPlus getToolBarMenuDockPlus() {
return null;
}
@Override
public JPanel getEastUpPane() {
return null;
}
@Override
public JPanel getEastDownPane() {
return null;
}
@Override
public ToolBarDef[] toolbars4Target() {
return new ToolBarDef[0];
}
@Override
public JPanel[] toolbarPanes4Form() {
return new JPanel[0];
}
@Override
public ShortCut[] shortcut4TemplateMenu() {
return new ShortCut[0];
}
@Override
public ShortCut[] shortCuts4Authority() {
return new ShortCut[0];
}
@Override
public JComponent[] toolBarButton4Form() {
return new JComponent[0];
}
@Override
public JComponent toolBar4Authority() {
return null;
}
@Override
public int getToolBarHeight() {
return 0;
}
@Override
public boolean isJWorkBook() {
return false;
}
@Override
public boolean isJVirtualTemplate() {
return true;
}
@Override
public HyperlinkGroupPane getHyperLinkPane(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) {
return null;
}
@Override
public HyperlinkGroupPane getHyperLinkPaneNoPop(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) {
return null;
}
@Override
public void setAuthorityMode(boolean isUpMode) {
}
@Override
public Icon getIcon() {
if (getFullPathName().endsWith("cpt")) {
return BaseUtils.readIcon("/com/fr/design/images/buttonicon/newcpts.png");
} else {
return BaseUtils.readIcon("/com/fr/web/images/form/new_form3.png");
}
}
@Override
protected void applyUndoState(BaseUndoState baseUndoState) {
}
}

5
designer_form/src/com/fr/design/mainframe/JForm.java

@ -142,6 +142,11 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
return false;
}
@Override
public boolean isJVirtualTemplate() {
return false;
}
/**
* 返回当前支持的超链界面pane
*

Loading…
Cancel
Save