10.0 #1

Merged
guy merged 2 commits from guy/open-fineui-swing:10.0 into 10.0 3 years ago
  1. 41
      src/main/java/com/tptj/tool/hg/fineui/swing/FineUIEngine.java
  2. 60
      src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java
  3. 6
      src/main/java/com/tptj/tool/hg/fineui/swing/element/Element.java
  4. 35
      src/main/java/com/tptj/tool/hg/fineui/swing/element/LabelElement.java
  5. 27
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/CenterAdaptType.java
  6. 3
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalAdaptType.java
  7. 9
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalType.java
  8. 16
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalAdaptType.java
  9. 7
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalType.java
  10. 28
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/BaseFineUILayout.java
  11. 43
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/CenterLayout.java
  12. 42
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/HorizontalLayout.java
  13. 42
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/VerticalLayout.java

41
src/main/java/com/tptj/tool/hg/fineui/swing/FineUIEngine.java

@ -11,6 +11,7 @@ import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.JPanelElement; import com.tptj.tool.hg.fineui.swing.element.JPanelElement;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
@ -46,7 +47,7 @@ public class FineUIEngine {
// 所以采用逐渐引入,逐渐调试的方式去逐渐覆盖, // 所以采用逐渐引入,逐渐调试的方式去逐渐覆盖,
// 待全面适配成功后应该可以直接引入fineui.min.js了 // 待全面适配成功后应该可以直接引入fineui.min.js了
engine = JsEngineMaker.newInstance(); engine = JsEngineMaker.newInstance();
JsProcess.create(engine.getEngine(),()->{ JsProcess.create(engine.getEngine(), () -> {
engine.importJs( engine.importJs(
//com/fr/fineui 目录下的都是fineui自身的源码 //com/fr/fineui 目录下的都是fineui自身的源码
"com/fr/fineui/core/0.foundation.js", "com/fr/fineui/core/0.foundation.js",
@ -163,55 +164,55 @@ public class FineUIEngine {
return this; return this;
} }
public void close(){ public void close() {
engine.close(); engine.close();
} }
public static Object trans(V8 v8,Object result){ public static Object trans(V8 v8, Object result) {
return JsEngineMaker.trans(v8,result); return JsEngineMaker.trans(v8, result);
} }
public static void close( Object value ){ public static void close(Object value) {
JsEngineMaker.close(value); JsEngineMaker.close(value);
} }
public static Object call(V8Object js, String method, Object ... args)throws Exception{ public static Object call(V8Object js, String method, Object... args) throws Exception {
//为了保证跨线程调用成功,在java中调用JS对象的方法时, //为了保证跨线程调用成功,在java中调用JS对象的方法时,
// 需要使用JsProcess.create(V8Object,Action)的方式 // 需要使用JsProcess.create(V8Object,Action)的方式
return JsProcess.create(js,()->{ return JsProcess.create(js, () -> {
return executeFunction(js, method, args); return executeFunction(js, method, args);
}).run(); }).run();
} }
public static Object executeFunction( V8Object js, String method, Object ... args ){ public static Object executeFunction(V8Object js, String method, Object... args) {
return JsEngineMaker.executeFunction(js, method, args); return JsEngineMaker.executeFunction(js, method, args);
} }
public static V8Array executeArrayFunction( V8Object js, String method, Object ... args ){ public static V8Array executeArrayFunction(V8Object js, String method, Object... args) {
return JsEngineMaker.executeArrayFunction(js, method, args); return JsEngineMaker.executeArrayFunction(js, method, args);
} }
public static V8Object executeObjectFunction( V8Object js, String method, Object ... args ){ public static V8Object executeObjectFunction(V8Object js, String method, Object... args) {
return JsEngineMaker.executeObjectFunction(js, method, args); return JsEngineMaker.executeObjectFunction(js, method, args);
} }
public static String executeStringFunction( V8Object js, String method, Object ... args ){ public static String executeStringFunction(V8Object js, String method, Object... args) {
return JsEngineMaker.executeStringFunction(js, method, args); return JsEngineMaker.executeStringFunction(js, method, args);
} }
public static boolean executeBooleanFunction( V8Object js, String method, Object ... args ){ public static boolean executeBooleanFunction(V8Object js, String method, Object... args) {
return JsEngineMaker.executeBooleanFunction(js, method, args); return JsEngineMaker.executeBooleanFunction(js, method, args);
} }
public static double executeDoubleFunction( V8Object js, String method, Object ... args ){ public static double executeDoubleFunction(V8Object js, String method, Object... args) {
return JsEngineMaker.executeDoubleFunction(js, method, args); return JsEngineMaker.executeDoubleFunction(js, method, args);
} }
public static int executeIntegerFunction( V8Object js, String method, Object ... args ){ public static int executeIntegerFunction(V8Object js, String method, Object... args) {
return JsEngineMaker.executeIntegerFunction(js, method, args); return JsEngineMaker.executeIntegerFunction(js, method, args);
} }
public static void executeVoidFunction( V8Object js, String method, Object ... args ){ public static void executeVoidFunction(V8Object js, String method, Object... args) {
JsEngineMaker.executeVoidFunction(js, method, args); JsEngineMaker.executeVoidFunction(js, method, args);
} }
@ -221,12 +222,12 @@ public class FineUIEngine {
//设计器插件本身其实也基本都是静态布局即可满足需要 //设计器插件本身其实也基本都是静态布局即可满足需要
JPanelElement el = new JPanelElement(); JPanelElement el = new JPanelElement();
FineUIEngine engine = FineUIEngine.getInstance(); FineUIEngine engine = FineUIEngine.getInstance();
JsProcess.create(engine.engine.getEngine(),()->{ JsProcess.create(engine.engine.getEngine(), () -> {
engine.body(el) engine.body(el)
//demo下面的就是实际使用时的代码了,该框架包开发完毕,使用者要写的就是按照demo目录下那些代码了 //demo下面的就是实际使用时的代码了,该框架包开发完毕,使用者要写的就是按照demo目录下那些代码了
//.importJs("com/tptj/tool/hg/fineui/swing/demo/layout.border.js"); // .importJs("com/tptj/tool/hg/fineui/swing/demo/layout.border.js");
//.importJs("com/tptj/tool/hg/fineui/swing/demo/layout.tape.js"); // .importJs("com/tptj/tool/hg/fineui/swing/demo/layout.tape.js");
//.importJs("com/tptj/tool/hg/fineui/swing/demo/layout.grid.js"); // .importJs("com/tptj/tool/hg/fineui/swing/demo/layout.grid.js");
.importJs("com/tptj/tool/hg/fineui/swing/demo/layout.window.js"); .importJs("com/tptj/tool/hg/fineui/swing/demo/layout.window.js");
return null; return null;
}).run(); }).run();
@ -236,7 +237,7 @@ public class FineUIEngine {
frame.setSize(800, 600); frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(el.getComponent()); frame.getContentPane().add(el.getWrapper());
frame.addWindowListener(new WindowListener() { frame.addWindowListener(new WindowListener() {
@Override @Override
public void windowOpened(WindowEvent e) { public void windowOpened(WindowEvent e) {

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

@ -7,6 +7,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 javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.util.*; import java.util.*;
@ -25,29 +26,31 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
private String type; private String type;
//记录当前的控件状态,用于驱动一些特殊事件 //记录当前的控件状态,用于驱动一些特殊事件
private Status status; private Status status;
public AbstractElement(T component) { public AbstractElement(T component) {
this.wrapper = component; this.wrapper = component;
this.component = component; this.component = component;
component.setOpaque(false);
} }
public void setComponent(T component) { public void setComponent(T component) {
this.wrapper = component; this.wrapper = component;
this.component = component; this.component = component;
component.setOpaque(false);
} }
private Map<String, Object> attributes = new HashMap<String, Object>(); private Map<String, Object> attributes = new HashMap<String, Object>();
private Map<String, Object> data = new HashMap<String, Object>(); private Map<String, Object> data = new HashMap<String, Object>();
private Set<String> clazz_set = new HashSet<String>(); private Set<String> clazz_set = new HashSet<String>();
private Map<String, Object> css = new HashMap<String, Object>(); private Map<String, Object> css = new HashMap<String, Object>();
private int width;
private int height;
private Object val; private Object val;
private AbstractElement parent; private AbstractElement parent;
private List<AbstractElement> children = new ArrayList<AbstractElement>(); private List<AbstractElement> children = new ArrayList<AbstractElement>();
public AbstractElement() { } public AbstractElement() {
}
public Status getStatus() { public Status getStatus() {
return status; return status;
@ -117,7 +120,7 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
case "background": case "background":
component.setOpaque(true); component.setOpaque(true);
Color color = ColorUtils.str2Color(val); Color color = ColorUtils.str2Color(val);
component.setBackground( color ); component.setBackground(color);
break; break;
case "color": case "color":
color = ColorUtils.str2Color(val); color = ColorUtils.str2Color(val);
@ -129,8 +132,6 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
css.put(name, val); css.put(name, val);
} }
@Override @Override
public Map<String, Object> getStyle() { public Map<String, Object> getStyle() {
return css; return css;
@ -140,7 +141,7 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
public void cssMap(V8Object map) { public void cssMap(V8Object map) {
String[] keys = map.getKeys(); String[] keys = map.getKeys();
for (String key : keys) { for (String key : keys) {
css(key, GeneralUtils.objectToString( map.get(key) ) ); css(key, GeneralUtils.objectToString(map.get(key)));
} }
} }
@ -154,6 +155,11 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
} }
@Override
public boolean hasScrollbar() {
return wrapper != component;
}
@Override @Override
public Object getData(String name) { public Object getData(String name) {
return data.get(name); return data.get(name);
@ -185,7 +191,7 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
component.setLayout(layout.init()); component.setLayout(layout.init());
for (int i = 0, len = children.size(); i < len; i++) { for (int i = 0, len = children.size(); i < len; i++) {
AbstractElement childElement = children.get(i); AbstractElement childElement = children.get(i);
layout.layout(childElement,i); layout.layout(childElement, i);
} }
} }
@ -219,13 +225,13 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
} }
@Override @Override
public void setWidth(int width) { public void setWidth(String width) {
this.width = width; css("width", width);
} }
@Override @Override
public void setHeight(int height) { public void setHeight(String height) {
this.height = height; css("height", height);
} }
@Override @Override
@ -243,11 +249,11 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
this.val = val; this.val = val;
} }
protected Object callJsMethod( String name, Object ... args ){ protected Object callJsMethod(String name, Object... args) {
try{ try {
return FineUIEngine.call(ref,name,args); return FineUIEngine.call(ref, name, args);
}catch(Exception e){ } catch (Exception e) {
FineLoggerFactory.getLogger().error(e,e.getMessage()); FineLoggerFactory.getLogger().error(e, e.getMessage());
} }
return null; return null;
} }
@ -258,22 +264,22 @@ public abstract class AbstractElement<T extends JComponent> implements Element<T
} }
@Override @Override
public int getRectStyleAttr( String name, int max, int min ){ public int getRectStyleAttr(String name, int max, int min) {
Object val = css.get(name); Object val = css.get(name);
if("".equals(val)){ if ("".equals(val)) {
return min; return min;
} }
if( null == val ){ if (null == val) {
return min; return min;
} }
if( val instanceof String && ((String)val).endsWith("%") ){ if (val instanceof String && ((String) val).endsWith("%")) {
String sv = (String)val; String sv = (String) val;
sv = sv.substring( 0, sv.length()-1 ); sv = sv.substring(0, sv.length() - 1);
double vald = GeneralUtils.objectToNumber(sv).doubleValue() * max ; double vald = GeneralUtils.objectToNumber(sv).doubleValue() * max;
vald = vald/100; vald = vald / 100;
return (int)vald; return (int) vald;
} }
return ( null == val || "initial".equals(val) || min > GeneralUtils.objectToNumber(val).intValue() ) return (null == val || "initial".equals(val) || min > GeneralUtils.objectToNumber(val).intValue())
? min : GeneralUtils.objectToNumber(val).intValue(); ? min : GeneralUtils.objectToNumber(val).intValue();
} }
} }

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

@ -18,6 +18,8 @@ public interface Element<T extends JComponent> {
void mounted(); void mounted();
JComponent getWrapper(); JComponent getWrapper();
boolean hasScrollbar();
Map<String,Object> getStyle(); Map<String,Object> getStyle();
int getRectStyleAttr( String name,int max, int min ); int getRectStyleAttr( String name,int max, int min );
@ -51,8 +53,8 @@ public interface Element<T extends JComponent> {
void appendTo( AbstractElement element ); void appendTo( AbstractElement element );
void appendChild( AbstractElement element ); void appendChild( AbstractElement element );
void setWidth(int width); void setWidth(String width);
void setHeight(int height); void setHeight(String height);
int getWidth(); int getWidth();
int getHeight(); int getHeight();

35
src/main/java/com/tptj/tool/hg/fineui/swing/element/LabelElement.java

@ -4,6 +4,7 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
/** /**
* @author 秃破天际 * @author 秃破天际
@ -17,26 +18,40 @@ public class LabelElement extends AbstractElement<UILabel> {
} }
@Override @Override
public Object getVal(){ public Object getVal() {
return getComponent().getText(); return getComponent().getText();
} }
@Override @Override
public void setVal( Object val ){ public void setVal(Object val) {
super.setVal(val); super.setVal(val);
getComponent().setText( GeneralUtils.objectToString(val) ); getComponent().setText(GeneralUtils.objectToString(val));
} }
@Override @Override
public void css(String name, String val) { public void css(String name, String val) {
super.css(name, val); super.css(name, val);
val = val.toUpperCase(); val = val.toUpperCase();
if( "text-align".equals( name ) ){ if ("text-align".equals(name)) {
if( "LEFT".equals(val) ){ if ("LEFT".equals(val)) {
getComponent().setHorizontalAlignment( SwingConstants.LEFT ); getComponent().setHorizontalAlignment(SwingConstants.LEFT);
}else if( "CENTER".equals(val) ){ } else if ("CENTER".equals(val)) {
getComponent().setHorizontalAlignment( SwingConstants.CENTER ); getComponent().setHorizontalAlignment(SwingConstants.CENTER);
}else if( "RIGHT".equals(val) ){ } else if ("RIGHT".equals(val)) {
getComponent().setHorizontalAlignment( SwingConstants.RIGHT ); getComponent().setHorizontalAlignment(SwingConstants.RIGHT);
}
}
Dimension dim = getComponent().getPreferredSize();
if ("width".equals(name)) {
if (val.length() > 0) {
dim.width = Integer.parseInt(val);
getComponent().setPreferredSize(dim);
}
}
if ("height".equals(name)) {
if (val.length() > 0) {
dim.height = Integer.parseInt(val);
getComponent().setPreferredSize(dim);
} }
} }
} }

27
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/CenterAdaptType.java

@ -1,6 +1,10 @@
package com.tptj.tool.hg.fineui.swing.element.layout; package com.tptj.tool.hg.fineui.swing.element.layout;
import com.tptj.tool.hg.fineui.swing.element.Element; import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.CenterLayout;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.HorizontalLayout;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.VerticalLayout;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -11,24 +15,19 @@ import java.awt.*;
* Created by 秃破天际 on 2021/11/1 * Created by 秃破天际 on 2021/11/1
**/ **/
public class CenterAdaptType extends AbstractLayoutType { public class CenterAdaptType extends AbstractLayoutType {
protected JComponent wrapComponent;
@Override @Override
public LayoutManager init() { public LayoutManager init() {
return new BoxLayout( element.getComponent(), BoxLayout.X_AXIS); wrapComponent = new JPanel();
wrapComponent.setOpaque(false);
wrapComponent.setLayout(new HorizontalLayout(element, FlowLayout.CENTER, 0, 0));
element.getComponent().add(wrapComponent);
return new VerticalLayout(element, VerticalFlowLayout.CENTER, 0, 0, true);
} }
@Override @Override
public void layout(Element child,int idx ) { public void layout(Element child, int idx) {
JComponent component = element.getComponent(); wrapComponent.add(child.getWrapper());
Box box = new Box(BoxLayout.Y_AXIS);
box.add(Box.createVerticalGlue());
box.add( child.getWrapper() );
box.add(Box.createVerticalGlue());
if (idx == 0) {
component.add(Box.createHorizontalGlue());
}
component.add(box);
if ( idx == element.children().size() - 1) {
component.add(Box.createHorizontalGlue());
}
} }
} }

3
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalAdaptType.java

@ -2,6 +2,7 @@ package com.tptj.tool.hg.fineui.swing.element.layout;
import com.tptj.tool.hg.fineui.swing.element.Element; import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout; import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.VerticalLayout;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -14,7 +15,7 @@ import java.awt.*;
public class HorizontalAdaptType extends AbstractLayoutType{ public class HorizontalAdaptType extends AbstractLayoutType{
@Override @Override
public LayoutManager init() { public LayoutManager init() {
return new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true); return new VerticalLayout(element, VerticalFlowLayout.TOP, 0, 0, true);
} }
@Override @Override

9
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalType.java

@ -1,15 +1,22 @@
package com.tptj.tool.hg.fineui.swing.element.layout; package com.tptj.tool.hg.fineui.swing.element.layout;
import com.tptj.tool.hg.fineui.swing.element.Element; import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.HorizontalLayout;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
/** /**
* @author 秃破天际 * @author 秃破天际
* @version 10.0 * @version 10.0
* Created by 秃破天际 on 2021/11/1 * Created by 秃破天际 on 2021/11/1
**/ **/
public class HorizontalType extends CenterAdaptType{ public class HorizontalType extends AbstractLayoutType{
@Override
public LayoutManager init() {
return new HorizontalLayout(element, FlowLayout.LEFT, 0, 0);
}
@Override @Override
public void layout(Element child, int idx) { public void layout(Element child, int idx) {

16
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalAdaptType.java

@ -1,8 +1,12 @@
package com.tptj.tool.hg.fineui.swing.element.layout; package com.tptj.tool.hg.fineui.swing.element.layout;
import com.tptj.tool.hg.fineui.swing.element.Element; import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.HorizontalLayout;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.VerticalLayout;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
/** /**
* @author 秃破天际 * @author 秃破天际
@ -11,11 +15,11 @@ import javax.swing.*;
**/ **/
public class VerticalAdaptType extends CenterAdaptType { public class VerticalAdaptType extends CenterAdaptType {
@Override @Override
public void layout(Element child, int idx ) { public LayoutManager init() {
Box box = new Box(BoxLayout.Y_AXIS); wrapComponent = new JPanel();
box.add(Box.createVerticalGlue()); wrapComponent.setOpaque(false);
box.add( child.getWrapper() ); wrapComponent.setLayout(new HorizontalLayout(element, FlowLayout.LEFT, 0, 0));
box.add(Box.createVerticalGlue()); element.getComponent().add(wrapComponent);
element.getComponent().add(box); return new VerticalLayout(element, VerticalFlowLayout.CENTER, 0, 0, true);
} }
} }

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

@ -2,6 +2,7 @@ package com.tptj.tool.hg.fineui.swing.element.layout;
import com.tptj.tool.hg.fineui.swing.element.Element; import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout; import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout;
import com.tptj.tool.hg.fineui.swing.element.layout.impl.VerticalLayout;
import java.awt.*; import java.awt.*;
@ -10,14 +11,14 @@ import java.awt.*;
* @version 10.0 * @version 10.0
* Created by 秃破天际 on 2021/11/1 * Created by 秃破天际 on 2021/11/1
**/ **/
public class VerticalType extends AbstractLayoutType{ public class VerticalType extends AbstractLayoutType {
@Override @Override
public LayoutManager init() { public LayoutManager init() {
return new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true); return new VerticalLayout(element, VerticalFlowLayout.TOP, 0, 0, true);
} }
@Override @Override
public void layout(Element child, int idx) { public void layout(Element child, int idx) {
element.getComponent().add( child.getWrapper() ); element.getComponent().add(child.getWrapper());
} }
} }

28
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/BaseFineUILayout.java

@ -13,9 +13,10 @@ import java.util.List;
**/ **/
public abstract class BaseFineUILayout implements LayoutManager2 { public abstract class BaseFineUILayout implements LayoutManager2 {
public static final int NOT_EXIST = -99999; public static final int NOT_EXIST = -99999;
public static final int MAX_SIZE = 99999;
protected Element element; protected Element element;
public BaseFineUILayout(Element element){ public BaseFineUILayout(Element element) {
this.element = element; this.element = element;
} }
@ -61,17 +62,30 @@ public abstract class BaseFineUILayout implements LayoutManager2 {
int p_height = 0; int p_height = 0;
int width = parent.getParent().getWidth(); int width = parent.getParent().getWidth();
int height = parent.getParent().getHeight(); int height = parent.getParent().getHeight();
for( Element child : children ){ for (Element child : children) {
Rectangle rect = getFineUIRect(child, width, height); Rectangle rect = getFineUIRect(child, width, height);
if( rect.x + rect.width > p_width ){ if (rect.x + rect.width > p_width) {
p_width = rect.x + rect.width; p_width = rect.x + rect.width;
} }
if( rect.y + rect.height > p_height ){ if (rect.y + rect.height > p_height) {
p_height = rect.y + rect.height; p_height = rect.y + rect.height;
} }
} }
int w = element.getRectStyleAttr("width", MAX_SIZE, NOT_EXIST);
int h = element.getRectStyleAttr("height", MAX_SIZE, NOT_EXIST);
Dimension realDim = new Dimension(w, h);
if (w == MAX_SIZE || w == NOT_EXIST) {
realDim.width = p_width;
}
if (h == MAX_SIZE || h == NOT_EXIST) {
realDim.height = p_height;
}
if (element.hasScrollbar()) {
element.getWrapper().setPreferredSize(realDim);
return new Dimension(p_width, p_height); return new Dimension(p_width, p_height);
} }
return realDim;
}
@Override @Override
public Dimension minimumLayoutSize(Container parent) { public Dimension minimumLayoutSize(Container parent) {
@ -83,13 +97,13 @@ public abstract class BaseFineUILayout implements LayoutManager2 {
int width = parent.getWidth(); int width = parent.getWidth();
int height = parent.getHeight(); int height = parent.getHeight();
List<AbstractElement> children = element.children(); List<AbstractElement> children = element.children();
for( Element child : children ){ for (Element child : children) {
Rectangle rect = getFineUIRect(child, width, height); Rectangle rect = getFineUIRect(child, width, height);
child.getComponent().setBounds(rect.x,rect.y,rect.width,rect.height); child.getWrapper().setBounds(rect.x, rect.y, rect.width, rect.height);
} }
} }
protected abstract Rectangle getFineUIRect(Element child,int width,int height); protected abstract Rectangle getFineUIRect(Element child, int width, int height);
} }

43
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/CenterLayout.java

@ -0,0 +1,43 @@
package com.tptj.tool.hg.fineui.swing.element.layout.impl;
import com.tptj.tool.hg.fineui.swing.element.Element;
import javax.swing.*;
import java.awt.*;
import static com.tptj.tool.hg.fineui.swing.element.layout.impl.BaseFineUILayout.MAX_SIZE;
import static com.tptj.tool.hg.fineui.swing.element.layout.impl.BaseFineUILayout.NOT_EXIST;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021/11/1
**/
public class CenterLayout extends BoxLayout {
protected Element element;
public CenterLayout(Element target, int axis) {
super(target.getComponent(), axis);
element = target;
}
@Override
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = super.preferredLayoutSize(parent);
int w = element.getRectStyleAttr("width", MAX_SIZE, NOT_EXIST);
int h = element.getRectStyleAttr("height", MAX_SIZE, NOT_EXIST);
Dimension realDim = new Dimension(w, h);
if (w == MAX_SIZE || w == NOT_EXIST) {
realDim.width = dim.width;
}
if (h == MAX_SIZE || h == NOT_EXIST) {
realDim.height = dim.height;
}
return realDim;
}
@Override
public void layoutContainer(Container parent) {
super.layoutContainer(parent);
}
}

42
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/HorizontalLayout.java

@ -0,0 +1,42 @@
package com.tptj.tool.hg.fineui.swing.element.layout.impl;
import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout;
import java.awt.*;
import static com.tptj.tool.hg.fineui.swing.element.layout.impl.BaseFineUILayout.MAX_SIZE;
import static com.tptj.tool.hg.fineui.swing.element.layout.impl.BaseFineUILayout.NOT_EXIST;
public class HorizontalLayout extends FlowLayout {
private Element element;
public HorizontalLayout(Element target, int align, int hgap, int vgap) {
super(align, hgap, vgap);
element = target;
}
@Override
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = super.preferredLayoutSize(parent);
int w = element.getRectStyleAttr("width", MAX_SIZE, NOT_EXIST);
int h = element.getRectStyleAttr("height", MAX_SIZE, NOT_EXIST);
Dimension realDim = new Dimension(w, h);
if (w == MAX_SIZE || w == NOT_EXIST) {
realDim.width = dim.width;
}
if (h == MAX_SIZE || h == NOT_EXIST) {
realDim.height = dim.height;
}
if (element.hasScrollbar()) {
element.getWrapper().setPreferredSize(realDim);
return dim;
}
return realDim;
}
@Override
public void layoutContainer(Container parent) {
super.layoutContainer(parent);
}
}

42
src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/VerticalLayout.java

@ -0,0 +1,42 @@
package com.tptj.tool.hg.fineui.swing.element.layout.impl;
import com.tptj.tool.hg.fineui.swing.element.Element;
import com.tptj.tool.hg.fineui.swing.element.VerticalFlowLayout;
import java.awt.*;
import static com.tptj.tool.hg.fineui.swing.element.layout.impl.BaseFineUILayout.MAX_SIZE;
import static com.tptj.tool.hg.fineui.swing.element.layout.impl.BaseFineUILayout.NOT_EXIST;
public class VerticalLayout extends VerticalFlowLayout {
private Element element;
public VerticalLayout(Element target, int align, int hgap, int vgap, boolean hfill) {
super(align, hgap, vgap, hfill);
element = target;
}
@Override
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = super.preferredLayoutSize(parent);
int w = element.getRectStyleAttr("width", MAX_SIZE, NOT_EXIST);
int h = element.getRectStyleAttr("height", MAX_SIZE, NOT_EXIST);
Dimension realDim = new Dimension(w, h);
if (w == MAX_SIZE || w == NOT_EXIST) {
realDim.width = dim.width;
}
if (h == MAX_SIZE || h == NOT_EXIST) {
realDim.height = dim.height;
}
if (element.hasScrollbar()) {
element.getWrapper().setPreferredSize(realDim);
return dim;
}
return realDim;
}
@Override
public void layoutContainer(Container parent) {
super.layoutContainer(parent);
}
}
Loading…
Cancel
Save