Browse Source

Merge pull request '10.0' (#4) from guy/open-fineui-swing:10.0 into 10.0

Reviewed-on: hugh/open-fineui-swing#4
10.0
guy 3 years ago
parent
commit
1c63b8aa6d
  1. 11
      src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java
  2. 1
      src/main/java/com/tptj/tool/hg/fineui/swing/element/ButtonElement.java
  3. 1
      src/main/java/com/tptj/tool/hg/fineui/swing/element/Element.java
  4. 1
      src/main/java/com/tptj/tool/hg/fineui/swing/element/ListElement.java
  5. 6
      src/main/resources/com/fr/fineui/core/wrapper/layout.js
  6. 39
      src/main/resources/com/tptj/tool/hg/fineui/swing/base/single/group.button.js
  7. 10
      src/main/resources/com/tptj/tool/hg/fineui/swing/core/element.js
  8. 2
      src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.horizontal.js
  9. 8
      src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.service.js
  10. 2
      src/main/resources/com/tptj/tool/hg/fineui/swing/core/wrapper/layout.vertical.js
  11. 4
      src/main/resources/com/tptj/tool/hg/fineui/swing/demo/group.button.js

11
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<T extends JComponent> implements Element<T> {
protected T component;
private JComponent wrapper;
protected JComponent wrapper;
private V8Object ref;
private String type;
//记录当前的控件状态,用于驱动一些特殊事件
@ -151,9 +152,14 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
}
@Override
public void updateUI() {
component.updateUI();
}
@Override
public void destroy() {
component.removeAll();
component.getParent().removeAll();
children.clear();
}
@ -185,6 +191,7 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
@Override
public void empty() {
children.clear();
component.removeAll();
}
@Override

1
src/main/java/com/tptj/tool/hg/fineui/swing/element/ButtonElement.java

@ -3,7 +3,6 @@ package com.tptj.tool.hg.fineui.swing.element;
import com.fr.general.GeneralUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

1
src/main/java/com/tptj/tool/hg/fineui/swing/element/Element.java

@ -37,6 +37,7 @@ public interface Element<T extends JComponent> {
void css(String name,String val);
void cssMap(V8Object map);
void unbind();
void updateUI();
void destroy();
void setData(String name,Object data);

1
src/main/java/com/tptj/tool/hg/fineui/swing/element/ListElement.java

@ -15,6 +15,7 @@ public class ListElement extends AbstractSingleElement<JList> {
public ListElement() {
super(new JList());
this.wrapper = new JScrollPane(component);
}
@Override

6
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)) {

39
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"
})
});
}());

10
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;
}

2
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);

8
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;
}

2
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);

4
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)"
},

Loading…
Cancel
Save