动态加图片选定控件,并且绑定事件原创
金蝶云社区-n_m
n_m
6人赞赏了该文章 904次浏览 未经作者许可,禁止转载编辑于2020年03月19日 17:21:55

如图例子:

image.png


实现代码:


@Override

public void afterCreateNewData(EventObject e) {

// TODO Auto-generated method stub

super.afterCreateNewData(e);

//创建flex面板

FlexPanelAp itemPanel1 = this.getItemPanel();

//创建菜单名

IconAp menuName = this.createMenuName();

//选择icon

VectorAp icon = this.createSelectIcon();

//创建label标签

LabelAp selectorMargin = this.createLabel();

itemPanel1.getItems().add(menuName);

itemPanel1.getItems().add(icon);

itemPanel1.getItems().add(selectorMargin);

List list = new ArrayList();

list.add(itemPanel1.createControl());

//flex加控件

Container panel = (Container)this.getControl("flexpanelap");

panel.addControls(list);

}

/**

* 动态绑定控件监听事件

*/

public void onGetControl(OnGetControlArgs e) {

super.onGetControl(e);

String key = e.getKey();

Vector vector;

if(key.startsWith("vectorap")) {

vector = new Vector();

vector.setKey(key);

vector.setView(this.getView());

vector.addClickListener(this);

e.setControl(vector);

}

}

/**

* 点击事件

*/

public void click(EventObject evt) {

Object source = evt.getSource();

String key = ((Control) source).getKey();

if(key.startsWith("vectorap")) {

Vector vectorIcon = (Vector)this.getView().getControl(key);

String selStr1 = this.getPageCache().get("cache_selectedNode");

if (selStr1 != null && "xuanzhong".equals(selStr1)) {

vectorIcon.setFontClass("kdfont kdfont-fuxuankuangweixuanzhong_yuan");

this.getPageCache().put("cache_selectedNode", "weixuanzhong");

} else {

vectorIcon.setFontClass("kdfont kdfont-fuxuankuangxuanzhong_yuan");

this.getPageCache().put("cache_selectedNode", "xuanzhong");

}

}

}

/**

* 创建flex面板

* @return FlexPanelAp

*/

public FlexPanelAp getItemPanel() {

FlexPanelAp itemPanel1 = new FlexPanelAp();

itemPanel1.setKey("panelap1");

itemPanel1.setDirection("row");

itemPanel1.setAlignItems("center");

itemPanel1.setGrow(0);

itemPanel1.setJustifyContent("center");

itemPanel1.setAlignItems("center");

itemPanel1.setShrink(0);

itemPanel1.setOverflow("hidden");

itemPanel1.setWidth(new LocaleString("100px"));

Style margin = itemPanel1.getStyle();

if(margin == null) {

margin = new Style();

}

Padding outerPanel = new Padding();

outerPanel.setLeft("5px");

outerPanel.setTop("5px");

outerPanel.setBottom("5px");

margin.setPadding(outerPanel);

itemPanel1.setStyle(margin);

return itemPanel1;

}


/**

* 创建菜单名

* @return

*/

public IconAp createMenuName() {

IconAp menuName = new IconAp();

menuName.setKey("iconap1");

menuName.setName(new LocaleString("momenuname"));

menuName.setImageKey("/icons/pc/entrance/default_48_48.png");

menuName.setHeight(new LocaleString("48px"));

menuName.setWidth(new LocaleString("48px"));

menuName.setRadius("6px");

Style margin = new Style();

Margin iconUrl = new Margin();

iconUrl.setBottom("3px");

margin.setMargin(iconUrl);

menuName.setStyle(margin);

return menuName;

}


/**

* 创建菜单名

* @return

*/

public VectorAp createSelectIcon() {

VectorAp icon = new VectorAp();

icon.setKey("vectorap1");

icon.setName(new LocaleString("moicon"));

//未选中

//选中为icon.setfontClass("kdfont kdfont-fuxuankuangxuanzhong_yuan");

icon.setfontClass("kdfont kdfont-fuxuankuangweixuanzhong_yuan");

icon.setFontSize(15);

icon.setForeColor("#007fff");

Style margin = icon.getStyle();

if(margin == null) {

margin = new Style();

}

Margin selector = new Margin();

selector.setTop("-48px");

selector.setLeft("2px");

margin.setMargin(selector);

icon.setStyle(margin);

icon.setAlignSelf("center");

return icon;

}


/**

* 创建label标签

* @return

*/

public LabelAp createLabel() {

LabelAp selectorMargin = new LabelAp();

selectorMargin.setKey("labelap1");

selectorMargin.setName(new LocaleString("momo"));

selectorMargin.setWidth(new LocaleString("95px"));

selectorMargin.setHeight(new LocaleString("31px"));

selectorMargin.setTextAlign("center");

selectorMargin.setAutoTextWrap(true);

selectorMargin.setShrink(0);

selectorMargin.setLineHeight("15px");

Style margin = selectorMargin.getStyle();

if(margin == null) {

margin = new Style();

}

Margin labelMenu = new Margin();

labelMenu.setLeft("-15px");

margin.setMargin(labelMenu);

selectorMargin.setStyle(margin);

return selectorMargin;

}


赞 6