Browse Source

合并IOFileAttrMark接口demo代码

10.0
hugh 4 years ago
parent
commit
c024ad27a1
  1. 6
      README.md
  2. 5
      plugin.xml
  3. 10
      src/main/java/com/tptj/demo/hg/menu/handler/DemoAction.java
  4. 64
      src/main/java/com/tptj/demo/hg/menu/handler/DemoAttrMark.java
  5. 38
      src/main/java/com/tptj/demo/hg/menu/handler/DemoPane.java

6
README.md

@ -1,4 +1,8 @@
# demo-menu-handler
设计器菜单扩展\
demo生效后,设计器的模板工具栏会增加一个叫demo的菜单项,点击会出现Demo Action的弹窗
demo生效后,设计器的模板工具栏会增加一个叫demo的菜单项,点击会出现Demo Action的弹窗\
增补IOFileAttrMark用例\
在Demo Action中可以输入一个txt文本(当前不支持特殊符号)。\
可以作为模板的额外属性跟模板一起保存\
测试可以用两个模板配置不同的txt分别打开查看

5
plugin.xml

@ -9,7 +9,10 @@
<description><![CDATA[ ]]></description>
<change-notes><![CDATA[]]></change-notes>
<main-package>com.tptj.demo.hg.menu.handler</main-package>
<function-recorder class="com.tptj.demo.hg.menu.handler.Demo"/>
<function-recorder class="com.tptj.demo.hg.menu.handler.DemoAttrMark"/>
<extra-core>
<IOFileAttrMark class="com.tptj.demo.hg.menu.handler.DemoAttrMark"/>
</extra-core>
<extra-designer>
<MenuHandler class="com.tptj.demo.hg.menu.handler.Demo"/>
</extra-designer>

10
src/main/java/com/tptj/demo/hg/menu/handler/DemoAction.java

@ -1,12 +1,11 @@
package com.tptj.demo.hg.menu.handler;
import com.fr.base.io.AttrMark;
import com.fr.base.svg.IconUtils;
import com.fr.design.actions.JTemplateAction;
import com.fr.design.dialog.*;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.intelli.record.Focus;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.report.fit.FitProvider;
import java.awt.*;
@ -17,7 +16,7 @@ import java.awt.event.ActionEvent;
* @version 10.0
* Created by 秃破天际 on 2021-05-20
**/
@EnableMetrics
public class DemoAction extends JTemplateAction {
private static final Dimension MEDIUM = new Dimension(430, 400);
public DemoAction(JTemplate template) {
@ -27,7 +26,6 @@ public class DemoAction extends JTemplateAction {
}
@Override
@Focus(id="com.tptj.demo.hg.menu.handler.v10",text = "MenuHandler")
public void actionPerformed(ActionEvent e) {
JTemplate jwb = getEditingComponent();
if ( null == jwb ) {
@ -40,14 +38,16 @@ public class DemoAction extends JTemplateAction {
}else{
//不是cpt
}
DemoPane pane = new DemoPane();
DemoPane pane = new DemoPane( (AttrMark) wbTpl );
UIDialog dialog = pane.showUnsizedWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() {
@Override
public void doOk() {
//做某些操作 从 pane中读取相关的交互结果设置到当前的模板中一般是这样
pane.update();
jwb.fireTargetModified();
}
});
pane.populate();
dialog.setSize(MEDIUM);
dialog.setVisible(true);
}

64
src/main/java/com/tptj/demo/hg/menu/handler/DemoAttrMark.java

@ -0,0 +1,64 @@
package com.tptj.demo.hg.menu.handler;
import com.fr.intelli.record.Focus;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.stable.StringUtils;
import com.fr.stable.fun.impl.AbstractIOFileAttrMark;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-05-20
**/
@EnableMetrics
public class DemoAttrMark extends AbstractIOFileAttrMark {
public final static String XML_TAG = "DemoAttrMark";
private String txt;
@Focus(id="com.tptj.demo.hg.menu.handler.v10",text = "MenuHandler")
public String getTxt() {
return txt;
}
public void setTxt(String txt) {
this.txt = txt;
}
@Override
public String xmlTag() {
return XML_TAG;
}
@Override
public void readXML(XMLableReader reader) {
String tag = reader.getTagName();
if( XML_TAG.equals(tag) ){
txt = reader.getAttrAsString("txt", StringUtils.EMPTY);
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_TAG).attr("txt",txt).end();
}
@Override
public DemoAttrMark clone() {
DemoAttrMark obj = (DemoAttrMark)super.clone();
obj.txt = txt;
return obj;
}
@Override
public JSONObject createJSONConfig() throws JSONException{
JSONObject json = super.createJSONConfig();
json.put("txt",txt);
return json;
}
}

38
src/main/java/com/tptj/demo/hg/menu/handler/DemoPane.java

@ -1,6 +1,15 @@
package com.tptj.demo.hg.menu.handler;
import com.fr.base.io.AttrMark;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import javax.swing.*;
import java.awt.*;
/**
* @author 秃破天际
@ -8,8 +17,37 @@ import com.fr.design.dialog.BasicPane;
* Created by 秃破天际 on 2021-05-20
**/
public class DemoPane extends BasicPane {
private UITextField w_txt;
private AttrMark container;
public DemoPane( AttrMark container ){
this.container = container;
w_txt = new UITextField();
setLayout(FRGUIPaneFactory.createM_BorderLayout());
JPanel pane = TableLayoutHelper.createTableLayoutPane(
new Component[][]{
{new UILabel("txt:"), w_txt}
},
new double[]{TableLayout.PREFERRED},
new double[]{ TableLayout.PREFERRED,TableLayout.FILL}
);
add( pane, BorderLayout.NORTH );
}
@Override
protected String title4PopupWindow() {
return "Demo Action";
}
public void populate(){
DemoAttrMark attr = container.getAttrMark(DemoAttrMark.XML_TAG);
if( null != attr ){
w_txt.setText( attr.getTxt() );
}
}
public void update(){
DemoAttrMark attr = new DemoAttrMark();
attr.setTxt( w_txt.getText() );
container.addAttrMark( attr );
}
}

Loading…
Cancel
Save