diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java index 44e04ff..e0e15d7 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java +++ b/src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java @@ -8,6 +8,7 @@ import com.tptj.tool.hg.fineui.swing.FineUIEngine; import com.tptj.tool.hg.fineui.swing.element.layout.LayoutBuilder; import com.tptj.tool.hg.fineui.swing.element.layout.LayoutType; import com.tptj.tool.hg.fineui.swing.stable.ColorUtils; +import org.nfunk.jep.function.Abs; import javax.swing.*; import java.awt.*; @@ -22,7 +23,7 @@ import java.util.List; public abstract class AbstractElement implements Element { protected T component; - private JComponent wrapper; + protected JComponent wrapper; private V8Object ref; private String type; //记录当前的控件状态,用于驱动一些特殊事件 @@ -151,9 +152,14 @@ public abstract class AbstractElement implements Element implements Element { void css(String name,String val); void cssMap(V8Object map); void unbind(); + void updateUI(); void destroy(); void setData(String name,Object data); diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/ListElement.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/ListElement.java index d3bb7c0..642b44c 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/ListElement.java +++ b/src/main/java/com/tptj/tool/hg/fineui/swing/element/ListElement.java @@ -15,6 +15,7 @@ public class ListElement extends AbstractSingleElement { public ListElement() { super(new JList()); + this.wrapper = new JScrollPane(component); } @Override diff --git a/src/main/resources/com/fr/fineui/core/wrapper/layout.js b/src/main/resources/com/fr/fineui/core/wrapper/layout.js index 7e43688..bc48cd3 100644 --- a/src/main/resources/com/fr/fineui/core/wrapper/layout.js +++ b/src/main/resources/com/fr/fineui/core/wrapper/layout.js @@ -83,7 +83,6 @@ BI.Layout = BI.inherit(BI.Widget, { }, appendFragment: function (frag) { - console.debug("appendFragment:frag",frag,this.element); this.element.append(frag); }, @@ -94,7 +93,7 @@ BI.Layout = BI.inherit(BI.Widget, { for (var key in this._children) { var child = this._children[key]; if (child.element !== self.element) { - frag.appendChild(child.element);//[0] hugh java没法实现这种非数组对象又能[]的 + frag.appendChild(child.element[0]); hasChild = true; } } @@ -241,7 +240,7 @@ BI.Layout = BI.inherit(BI.Widget, { var w = this._newElement(newIndex, item); // 需要有个地方临时存一下新建的组件,否则如果直接使用newIndex的话,newIndex位置的元素可能会被用到 this._children[this._getChildName(newIndex) + "-temp"] = w; - var nextSibling = del.element[0].nextSibling; + var nextSibling = del.element.next(); if (nextSibling) { BI.Widget._renderEngine.createElement(nextSibling).before(w.element); } else { @@ -421,6 +420,7 @@ BI.Layout = BI.inherit(BI.Widget, { var shouldUpdate = this.shouldUpdateItem(oldIndex, vnode); var child = this._children[this._getChildName(oldIndex)]; if (shouldUpdate) { + this._children[this._getChildName(newIndex) + "-temp"] = child; return child._update(this._getOptions(vnode), shouldUpdate); } if (shouldUpdate === null && !this._compare(oldVnode, vnode)) { diff --git a/src/main/resources/com/tptj/tool/hg/fineui/swing/base/single/group.button.js b/src/main/resources/com/tptj/tool/hg/fineui/swing/base/single/group.button.js index e69d735..ba8ba8a 100644 --- a/src/main/resources/com/tptj/tool/hg/fineui/swing/base/single/group.button.js +++ b/src/main/resources/com/tptj/tool/hg/fineui/swing/base/single/group.button.js @@ -22,24 +22,47 @@ var Widget = BI.inherit(BI.Widget, { render: function () { var self = this, o = this.options; + var layout = o.layouts[0]; + if (layout.scrollable) { + this.element.css("overflow", "auto"); + } + if (layout.scrollx) { + this.element.css("overflow-x", "auto"); + } + if (layout.scrolly) { + this.element.css("overflow-y", "auto"); + } this.populate(o.items); }, + _mountChildren: function () { + var self = this, o = this.options; + for (var key in this._children) { + var child = this._children[key]; + if (child.element !== self.element) { + this.element.append(child.element); + } + } + BI.Services.getService("swing.layout.service").layout(this.element, o.layouts[0]); + }, + populate: function (items) { var self = this, o = this.options; - this.element.populate(BI.map(items, function (i, item) { - return item.text; - })) + this.element.empty(); + this._children = []; + BI.each(items, function (i, item) { + self._children.push(BI.createWidget(item)); + }); + this._mountChildren(); + this.element.updateUI(); } }); BI.shortcut("swing.button_group", Widget); - var Button = Java.type("com.tptj.tool.hg.fineui.swing.element.ListElement"); - + // 这里仅实现通过button_group来动态创建组件并能刷新的功能 BI.config("bi.button_group", function (config) { - return BI.extend({}, config, { - type: "swing.button_group", - swingElement: Button + return BI.extend({}, config,{ + type: "swing.button_group" }) }); }()); diff --git a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/element.js b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/element.js index aca146d..775b3f6 100644 --- a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/element.js +++ b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/element.js @@ -7,6 +7,9 @@ var Element = Java.type("com.tptj.tool.hg.fineui.swing.element.JPanelElement"); $ = function (widget) { + if (widget instanceof SwingElement) { + return widget; + } return new SwingElement(widget); }; @@ -46,6 +49,7 @@ }, // 生命周期钩子 mounted: function () { + this._isMounted = true; this.java_el.mounted(); }, ref: function (obj) { @@ -75,6 +79,11 @@ this.java_el.unbind(); return this; }, + updateUI: function () { + if (this._isMounted) { + this.java_el.updateUI(); + } + }, destroy: function () { this.java_el.destroy(); }, @@ -107,7 +116,6 @@ } } else { this._children.push(element); - debugger; this.java_el.append(element.java_el); element._parent = this; } diff --git a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.horizontal.js b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.horizontal.js index a1fe165..1a998ff 100644 --- a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.horizontal.js +++ b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.horizontal.js @@ -8,7 +8,7 @@ this.element.append(child.element); } } - BI.Services.getService("swing.layout.service").layout(this); + BI.Services.getService("swing.layout.service").layout(this.element, o); } }); BI.shortcut("swing.horizontal", BI.SwingHorizontalLayout); diff --git a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.service.js b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.service.js index ab1cb88..66c8215 100644 --- a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.service.js +++ b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.service.js @@ -1,8 +1,6 @@ !(function () { var Service = BI.inherit(BI.OB, { - layout: function (widget) { - var element = widget.element; - var o = widget.options; + layout: function (element, o) { if (o.verticalAlign === BI.VerticalAlign.Middle) { if (o.horizontalAlign === BI.HorizontalAlign.Center) { element.layout("center_adapt"); @@ -15,11 +13,11 @@ element.layout("horizontal_adapt"); return; } - if (o.type === "swing.vertical") { + if (o.type === "swing.vertical" || o.type === "bi.vertical") { element.layout("vertical"); return; } - if (o.type === "swing.horizontal") { + if (o.type === "swing.horizontal" || o.type === "bi.horizontal") { element.layout("horizontal"); return; } diff --git a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.vertical.js b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.vertical.js index fcddc9e..f96e94b 100644 --- a/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.vertical.js +++ b/src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.vertical.js @@ -8,7 +8,7 @@ this.element.append(child.element); } } - BI.Services.getService("swing.layout.service").layout(this); + BI.Services.getService("swing.layout.service").layout(this.element, o); } }); BI.shortcut("swing.vertical", Widget); diff --git a/src/main/resources/com/tptj/tool/hg/fineui/swing/demo/group.button.js b/src/main/resources/com/tptj/tool/hg/fineui/swing/demo/group.button.js index 9e0cc79..5937b39 100644 --- a/src/main/resources/com/tptj/tool/hg/fineui/swing/demo/group.button.js +++ b/src/main/resources/com/tptj/tool/hg/fineui/swing/demo/group.button.js @@ -3,8 +3,10 @@ state: function () { return { items: [{ + type: "bi.label", text: "列表项1" }, { + type: "bi.label", text: "列表项2" }] } @@ -12,6 +14,7 @@ actions: { addItem: function () { this.model.items.push({ + type: "bi.label", text: "列表项" + (this.model.items.length + 1) }) } @@ -57,7 +60,6 @@ hgap: 30, scrollable: true }], - chooseType: BI.Selection.None, css: { background: "rgb(200,200,200)" },