Browse Source

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

Reviewed-on: hugh/open-fineui-swing#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. 54
      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
public void updateUI() {
component.updateUI();
wrapper.updateUI();
}
@Override
public void destroy() {
component.getParent().removeAll();
children.clear();
// wrapper.getParent().remove(wrapper);
// children.clear();
}
@Override
@ -192,6 +192,7 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
public void empty() {
children.clear();
component.removeAll();
component.setLayout(null);
}
@Override

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

@ -1,60 +1,24 @@
/**
* Created by GUY on 2015/6/26.
* 属性
* textAlign
* whiteSpace
* textWidth
* textHeight
* highLight
* keyword
* py
* handler
* 方法
* setText
* setStyle
* doRedMark
* unRedMark
* doHighLight
* unHighLight
* Created by GUY on 2021/11/7.
*/
!(function () {
// 实现一个简易版的ButtonGroup,FineUI中的ButtonGroup太复杂了。而且对于要单选多选这种功能,应该交给具体的List组件去解决。本ButtonGroup主要职责是在布局的基础之上提供刷新的功能
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);
// 将布局中的属性要处理下
return BI.extend({}, layout, {
ref: function (_ref) {
self.list = _ref;
},
_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]);
items: o.items
})
},
populate: function (items) {
var self = this, o = this.options;
this.element.empty();
this._children = [];
BI.each(items, function (i, item) {
self._children.push(BI.createWidget(item));
});
this._mountChildren();
this.element.updateUI();
this.list.populate(items);
}
});
BI.shortcut("swing.button_group", Widget);

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);
},
// 布局刷新不采用虚拟dom比较,都采用清空刷新
update: function (opt) {
this.element.empty();
this.forceUpdate(opt);
this.element.updateUI();
}
});
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 () {
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, {
layout: function (element, o) {
if (o.verticalAlign === BI.VerticalAlign.Middle) {
if (o.horizontalAlign === BI.HorizontalAlign.Center) {
var config = BI.extend({}, DEFAULT_CONFIG[o.type], o);
if (config.verticalAlign === BI.VerticalAlign.Middle) {
if (config.horizontalAlign === BI.HorizontalAlign.Center) {
element.layout("center_adapt");
return;
}
element.layout("vertical_adapt");
return;
}
if (o.horizontalAlign === BI.HorizontalAlign.Center) {
if (config.horizontalAlign === BI.HorizontalAlign.Center) {
element.layout("horizontal_adapt");
return;
}
if (o.type === "swing.vertical" || o.type === "bi.vertical") {
if (config.type === "swing.vertical" || config.type === "bi.vertical") {
element.layout("vertical");
return;
}
if (o.type === "swing.horizontal" || o.type === "bi.horizontal") {
if (config.type === "swing.horizontal" || config.type === "bi.horizontal") {
element.layout("horizontal");
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);
},
// 布局刷新不采用虚拟dom比较,都采用清空刷新
update: function (opt) {
this.element.empty();
this.forceUpdate(opt);
this.element.updateUI();
}
});
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;
},
layouts: [{
type: "bi.vertical_adapt",
verticalAlign: BI.VerticalAlign.Middle,
type: "bi.vertical",
hgap: 30,
scrollable: true
}],

Loading…
Cancel
Save