Browse Source

Merge pull request 'feature:优化button_group' (#5) from guy/open-fineui-swing:10.0 into 10.0

Reviewed-on: #5
10.0
guy 3 years ago
parent
commit
cddbeb1049
  1. 7
      src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java
  2. 58
      src/main/resources/com/tptj/tool/hg/fineui/swing/base/single/group.button.js
  3. 7
      src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.horizontal.js
  4. 33
      src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.service.js
  5. 7
      src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.vertical.js
  6. 3
      src/main/resources/com/tptj/tool/hg/fineui/swing/demo/group.button.js

7
src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java

@ -154,13 +154,13 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
@Override @Override
public void updateUI() { public void updateUI() {
component.updateUI(); wrapper.updateUI();
} }
@Override @Override
public void destroy() { public void destroy() {
component.getParent().removeAll(); // wrapper.getParent().remove(wrapper);
children.clear(); // children.clear();
} }
@Override @Override
@ -192,6 +192,7 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
public void empty() { public void empty() {
children.clear(); children.clear();
component.removeAll(); component.removeAll();
component.setLayout(null);
} }
@Override @Override

58
src/main/resources/com/tptj/tool/hg/fineui/swing/base/single/group.button.js

@ -1,67 +1,31 @@
/** /**
* Created by GUY on 2015/6/26. * Created by GUY on 2021/11/7.
* 属性
* textAlign
* whiteSpace
* textWidth
* textHeight
* highLight
* keyword
* py
* handler
* 方法
* setText
* setStyle
* doRedMark
* unRedMark
* doHighLight
* unHighLight
*/ */
!(function () { !(function () {
// 实现一个简易版的ButtonGroup,FineUI中的ButtonGroup太复杂了。而且对于要单选多选这种功能,应该交给具体的List组件去解决。本ButtonGroup主要职责是在布局的基础之上提供刷新的功能
var Widget = BI.inherit(BI.Widget, { var Widget = BI.inherit(BI.Widget, {
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
var layout = o.layouts[0]; var layout = o.layouts[0];
if (layout.scrollable) { // 将布局中的属性要处理下
this.element.css("overflow", "auto"); return BI.extend({}, layout, {
} ref: function (_ref) {
if (layout.scrollx) { self.list = _ref;
this.element.css("overflow-x", "auto"); },
} items: o.items
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) { populate: function (items) {
var self = this, o = this.options; this.list.populate(items);
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); BI.shortcut("swing.button_group", Widget);
// 这里仅实现通过button_group来动态创建组件并能刷新的功能 // 这里仅实现通过button_group来动态创建组件并能刷新的功能
BI.config("bi.button_group", function (config) { BI.config("bi.button_group", function (config) {
return BI.extend({}, config,{ return BI.extend({}, config, {
type: "swing.button_group" type: "swing.button_group"
}) })
}); });

7
src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.horizontal.js

@ -9,6 +9,13 @@
} }
} }
BI.Services.getService("swing.layout.service").layout(this.element, o); BI.Services.getService("swing.layout.service").layout(this.element, o);
},
// 布局刷新不采用虚拟dom比较,都采用清空刷新
update: function (opt) {
this.element.empty();
this.forceUpdate(opt);
this.element.updateUI();
} }
}); });
BI.shortcut("swing.horizontal", BI.SwingHorizontalLayout); BI.shortcut("swing.horizontal", BI.SwingHorizontalLayout);

33
src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.service.js

@ -1,23 +1,46 @@
!(function () { !(function () {
var DEFAULT_CONFIG = {
"bi.vertical_adapt": {
verticalAlign: BI.VerticalAlign.Middle
},
"swing.vertical_adapt": {
verticalAlign: BI.VerticalAlign.Middle
},
"bi.horizontal_adapt": {
horizontalAlign: BI.HorizontalAlign.Center
},
"swing.horizontal_adapt": {
horizontalAlign: BI.HorizontalAlign.Center
},
"bi.center_adapt": {
verticalAlign: BI.VerticalAlign.Middle,
horizontalAlign: BI.HorizontalAlign.Center
},
"swing.center_adapt": {
verticalAlign: BI.VerticalAlign.Middle,
horizontalAlign: BI.HorizontalAlign.Center
}
}
var Service = BI.inherit(BI.OB, { var Service = BI.inherit(BI.OB, {
layout: function (element, o) { layout: function (element, o) {
if (o.verticalAlign === BI.VerticalAlign.Middle) { var config = BI.extend({}, DEFAULT_CONFIG[o.type], o);
if (o.horizontalAlign === BI.HorizontalAlign.Center) { if (config.verticalAlign === BI.VerticalAlign.Middle) {
if (config.horizontalAlign === BI.HorizontalAlign.Center) {
element.layout("center_adapt"); element.layout("center_adapt");
return; return;
} }
element.layout("vertical_adapt"); element.layout("vertical_adapt");
return; return;
} }
if (o.horizontalAlign === BI.HorizontalAlign.Center) { if (config.horizontalAlign === BI.HorizontalAlign.Center) {
element.layout("horizontal_adapt"); element.layout("horizontal_adapt");
return; return;
} }
if (o.type === "swing.vertical" || o.type === "bi.vertical") { if (config.type === "swing.vertical" || config.type === "bi.vertical") {
element.layout("vertical"); element.layout("vertical");
return; return;
} }
if (o.type === "swing.horizontal" || o.type === "bi.horizontal") { if (config.type === "swing.horizontal" || config.type === "bi.horizontal") {
element.layout("horizontal"); element.layout("horizontal");
return; return;
} }

7
src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.vertical.js

@ -9,6 +9,13 @@
} }
} }
BI.Services.getService("swing.layout.service").layout(this.element, o); BI.Services.getService("swing.layout.service").layout(this.element, o);
},
// 布局刷新不采用虚拟dom比较,都采用清空刷新
update: function (opt) {
this.element.empty();
this.forceUpdate(opt);
this.element.updateUI();
} }
}); });
BI.shortcut("swing.vertical", Widget); BI.shortcut("swing.vertical", Widget);

3
src/main/resources/com/tptj/tool/hg/fineui/swing/demo/group.button.js

@ -55,8 +55,7 @@
self.list = _ref; self.list = _ref;
}, },
layouts: [{ layouts: [{
type: "bi.vertical_adapt", type: "bi.vertical",
verticalAlign: BI.VerticalAlign.Middle,
hgap: 30, hgap: 30,
scrollable: true scrollable: true
}], }],

Loading…
Cancel
Save