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. 37
      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.LayoutBuilder;
import com.tptj.tool.hg.fineui.swing.element.layout.LayoutType; import com.tptj.tool.hg.fineui.swing.element.layout.LayoutType;
import com.tptj.tool.hg.fineui.swing.stable.ColorUtils; import com.tptj.tool.hg.fineui.swing.stable.ColorUtils;
import org.nfunk.jep.function.Abs;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -22,7 +23,7 @@ import java.util.List;
public abstract class AbstractElement<T extends JComponent> implements Element<T> { public abstract class AbstractElement<T extends JComponent> implements Element<T> {
protected T component; protected T component;
private JComponent wrapper; protected JComponent wrapper;
private V8Object ref; private V8Object ref;
private String type; private String type;
//记录当前的控件状态,用于驱动一些特殊事件 //记录当前的控件状态,用于驱动一些特殊事件
@ -151,9 +152,14 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
} }
@Override
public void updateUI() {
component.updateUI();
}
@Override @Override
public void destroy() { public void destroy() {
component.removeAll(); component.getParent().removeAll();
children.clear(); children.clear();
} }
@ -185,6 +191,7 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
@Override @Override
public void empty() { public void empty() {
children.clear(); children.clear();
component.removeAll();
} }
@Override @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 com.fr.general.GeneralUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; 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 css(String name,String val);
void cssMap(V8Object map); void cssMap(V8Object map);
void unbind(); void unbind();
void updateUI();
void destroy(); void destroy();
void setData(String name,Object data); 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() { public ListElement() {
super(new JList()); super(new JList());
this.wrapper = new JScrollPane(component);
} }
@Override @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) { appendFragment: function (frag) {
console.debug("appendFragment:frag",frag,this.element);
this.element.append(frag); this.element.append(frag);
}, },
@ -94,7 +93,7 @@ BI.Layout = BI.inherit(BI.Widget, {
for (var key in this._children) { for (var key in this._children) {
var child = this._children[key]; var child = this._children[key];
if (child.element !== self.element) { if (child.element !== self.element) {
frag.appendChild(child.element);//[0] hugh java没法实现这种非数组对象又能[]的 frag.appendChild(child.element[0]);
hasChild = true; hasChild = true;
} }
} }
@ -241,7 +240,7 @@ BI.Layout = BI.inherit(BI.Widget, {
var w = this._newElement(newIndex, item); var w = this._newElement(newIndex, item);
// 需要有个地方临时存一下新建的组件,否则如果直接使用newIndex的话,newIndex位置的元素可能会被用到 // 需要有个地方临时存一下新建的组件,否则如果直接使用newIndex的话,newIndex位置的元素可能会被用到
this._children[this._getChildName(newIndex) + "-temp"] = w; this._children[this._getChildName(newIndex) + "-temp"] = w;
var nextSibling = del.element[0].nextSibling; var nextSibling = del.element.next();
if (nextSibling) { if (nextSibling) {
BI.Widget._renderEngine.createElement(nextSibling).before(w.element); BI.Widget._renderEngine.createElement(nextSibling).before(w.element);
} else { } else {
@ -421,6 +420,7 @@ BI.Layout = BI.inherit(BI.Widget, {
var shouldUpdate = this.shouldUpdateItem(oldIndex, vnode); var shouldUpdate = this.shouldUpdateItem(oldIndex, vnode);
var child = this._children[this._getChildName(oldIndex)]; var child = this._children[this._getChildName(oldIndex)];
if (shouldUpdate) { if (shouldUpdate) {
this._children[this._getChildName(newIndex) + "-temp"] = child;
return child._update(this._getOptions(vnode), shouldUpdate); return child._update(this._getOptions(vnode), shouldUpdate);
} }
if (shouldUpdate === null && !this._compare(oldVnode, vnode)) { if (shouldUpdate === null && !this._compare(oldVnode, vnode)) {

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

@ -22,24 +22,47 @@
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];
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); 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; var self = this, o = this.options;
this.element.populate(BI.map(items, function (i, item) { this.element.empty();
return item.text; 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);
var Button = Java.type("com.tptj.tool.hg.fineui.swing.element.ListElement"); // 这里仅实现通过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"
swingElement: Button
}) })
}); });
}()); }());

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"); var Element = Java.type("com.tptj.tool.hg.fineui.swing.element.JPanelElement");
$ = function (widget) { $ = function (widget) {
if (widget instanceof SwingElement) {
return widget;
}
return new SwingElement(widget); return new SwingElement(widget);
}; };
@ -46,6 +49,7 @@
}, },
// 生命周期钩子 // 生命周期钩子
mounted: function () { mounted: function () {
this._isMounted = true;
this.java_el.mounted(); this.java_el.mounted();
}, },
ref: function (obj) { ref: function (obj) {
@ -75,6 +79,11 @@
this.java_el.unbind(); this.java_el.unbind();
return this; return this;
}, },
updateUI: function () {
if (this._isMounted) {
this.java_el.updateUI();
}
},
destroy: function () { destroy: function () {
this.java_el.destroy(); this.java_el.destroy();
}, },
@ -107,7 +116,6 @@
} }
} else { } else {
this._children.push(element); this._children.push(element);
debugger;
this.java_el.append(element.java_el); this.java_el.append(element.java_el);
element._parent = this; 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); 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); 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 () { !(function () {
var Service = BI.inherit(BI.OB, { var Service = BI.inherit(BI.OB, {
layout: function (widget) { layout: function (element, o) {
var element = widget.element;
var o = widget.options;
if (o.verticalAlign === BI.VerticalAlign.Middle) { if (o.verticalAlign === BI.VerticalAlign.Middle) {
if (o.horizontalAlign === BI.HorizontalAlign.Center) { if (o.horizontalAlign === BI.HorizontalAlign.Center) {
element.layout("center_adapt"); element.layout("center_adapt");
@ -15,11 +13,11 @@
element.layout("horizontal_adapt"); element.layout("horizontal_adapt");
return; return;
} }
if (o.type === "swing.vertical") { if (o.type === "swing.vertical" || o.type === "bi.vertical") {
element.layout("vertical"); element.layout("vertical");
return; return;
} }
if (o.type === "swing.horizontal") { if (o.type === "swing.horizontal" || o.type === "bi.horizontal") {
element.layout("horizontal"); element.layout("horizontal");
return; 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); 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); 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 () { state: function () {
return { return {
items: [{ items: [{
type: "bi.label",
text: "列表项1" text: "列表项1"
}, { }, {
type: "bi.label",
text: "列表项2" text: "列表项2"
}] }]
} }
@ -12,6 +14,7 @@
actions: { actions: {
addItem: function () { addItem: function () {
this.model.items.push({ this.model.items.push({
type: "bi.label",
text: "列表项" + (this.model.items.length + 1) text: "列表项" + (this.model.items.length + 1)
}) })
} }
@ -57,7 +60,6 @@
hgap: 30, hgap: 30,
scrollable: true scrollable: true
}], }],
chooseType: BI.Selection.None,
css: { css: {
background: "rgb(200,200,200)" background: "rgb(200,200,200)"
}, },

Loading…
Cancel
Save