From 87d937dcfdb133e4e920e89c364a922b0b1c0965 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 6 Nov 2021 00:09:23 +0800 Subject: [PATCH] =?UTF-8?q?feature:=E5=B8=83=E5=B1=80=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tool/hg/fineui/swing/FineUIEngine.java | 39 +++++------ .../fineui/swing/element/AbstractElement.java | 64 ++++++++++--------- .../tool/hg/fineui/swing/element/Element.java | 6 +- .../hg/fineui/swing/element/LabelElement.java | 31 ++++++--- .../swing/element/layout/CenterAdaptType.java | 27 ++++---- .../element/layout/HorizontalAdaptType.java | 3 +- .../swing/element/layout/HorizontalType.java | 9 ++- .../element/layout/VerticalAdaptType.java | 16 +++-- .../swing/element/layout/VerticalType.java | 7 +- .../element/layout/impl/BaseFineUILayout.java | 30 ++++++--- .../element/layout/impl/CenterLayout.java | 43 +++++++++++++ .../element/layout/impl/HorizontalLayout.java | 42 ++++++++++++ .../element/layout/impl/VerticalLayout.java | 42 ++++++++++++ 13 files changed, 266 insertions(+), 93 deletions(-) create mode 100644 src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/CenterLayout.java create mode 100644 src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/HorizontalLayout.java create mode 100644 src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/VerticalLayout.java diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/FineUIEngine.java b/src/main/java/com/tptj/tool/hg/fineui/swing/FineUIEngine.java index b272217..081823c 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/FineUIEngine.java +++ b/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 javax.swing.*; +import java.awt.*; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; @@ -46,7 +47,7 @@ public class FineUIEngine { // 所以采用逐渐引入,逐渐调试的方式去逐渐覆盖, // 待全面适配成功后应该可以直接引入fineui.min.js了 engine = JsEngineMaker.newInstance(); - JsProcess.create(engine.getEngine(),()->{ + JsProcess.create(engine.getEngine(), () -> { engine.importJs( //com/fr/fineui 目录下的都是fineui自身的源码 "com/fr/fineui/core/0.foundation.js", @@ -163,55 +164,55 @@ public class FineUIEngine { return this; } - public void close(){ + public void close() { engine.close(); } - public static Object trans(V8 v8,Object result){ - return JsEngineMaker.trans(v8,result); + public static Object trans(V8 v8, Object result) { + return JsEngineMaker.trans(v8, result); } - public static void close( Object value ){ + public static void close(Object 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对象的方法时, // 需要使用JsProcess.create(V8Object,Action)的方式 - return JsProcess.create(js,()->{ + return JsProcess.create(js, () -> { return executeFunction(js, method, args); }).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); } - 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); } - 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); } - 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); } - 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); } - 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); } - 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); } - 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); } @@ -221,11 +222,11 @@ public class FineUIEngine { //设计器插件本身其实也基本都是静态布局即可满足需要 JPanelElement el = new JPanelElement(); FineUIEngine engine = FineUIEngine.getInstance(); - JsProcess.create(engine.engine.getEngine(),()->{ + JsProcess.create(engine.engine.getEngine(), () -> { engine.body(el) //demo下面的就是实际使用时的代码了,该框架包开发完毕,使用者要写的就是按照demo目录下那些代码了 - //.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.border.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.window.js"); return null; @@ -236,7 +237,7 @@ public class FineUIEngine { frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.getContentPane().add(el.getComponent()); + frame.getContentPane().add(el.getWrapper()); frame.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java index fd0c707..27ff3f8 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/AbstractElement.java +++ b/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.LayoutType; import com.tptj.tool.hg.fineui.swing.stable.ColorUtils; + import javax.swing.*; import java.awt.*; import java.util.*; @@ -25,29 +26,31 @@ public abstract class AbstractElement implements Element attributes = new HashMap(); private Map data = new HashMap(); private Set clazz_set = new HashSet(); private Map css = new HashMap(); - private int width; - private int height; private Object val; private AbstractElement parent; private List children = new ArrayList(); - public AbstractElement() { } + public AbstractElement() { + } public Status getStatus() { return status; @@ -116,11 +119,11 @@ public abstract class AbstractElement implements Element implements Element getStyle() { return css; @@ -140,7 +141,7 @@ public abstract class AbstractElement implements Element implements Element implements Element implements Element implements Element implements Element GeneralUtils.objectToNumber(val).intValue() ) + return (null == val || "initial".equals(val) || min > GeneralUtils.objectToNumber(val).intValue()) ? min : GeneralUtils.objectToNumber(val).intValue(); } } diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/Element.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/Element.java index a7f60a6..96505b8 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/Element.java +++ b/src/main/java/com/tptj/tool/hg/fineui/swing/element/Element.java @@ -18,6 +18,8 @@ public interface Element { void mounted(); JComponent getWrapper(); + boolean hasScrollbar(); + Map getStyle(); int getRectStyleAttr( String name,int max, int min ); @@ -51,8 +53,8 @@ public interface Element { void appendTo( AbstractElement element ); void appendChild( AbstractElement element ); - void setWidth(int width); - void setHeight(int height); + void setWidth(String width); + void setHeight(String height); int getWidth(); int getHeight(); diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/LabelElement.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/LabelElement.java index 75585c0..9fe4d41 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/LabelElement.java +++ b/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 javax.swing.*; +import java.awt.*; /** * @author 秃破天际 @@ -17,27 +18,37 @@ public class LabelElement extends AbstractElement { } @Override - public Object getVal(){ + public Object getVal() { return getComponent().getText(); } @Override - public void setVal( Object val ){ + public void setVal(Object val) { super.setVal(val); - getComponent().setText( GeneralUtils.objectToString(val) ); + getComponent().setText(GeneralUtils.objectToString(val)); } + @Override public void css(String name, String val) { super.css(name, val); val = val.toUpperCase(); - if( "text-align".equals( name ) ){ - if( "LEFT".equals(val) ){ - getComponent().setHorizontalAlignment( SwingConstants.LEFT ); - }else if( "CENTER".equals(val) ){ - getComponent().setHorizontalAlignment( SwingConstants.CENTER ); - }else if( "RIGHT".equals(val) ){ - getComponent().setHorizontalAlignment( SwingConstants.RIGHT ); + if ("text-align".equals(name)) { + if ("LEFT".equals(val)) { + getComponent().setHorizontalAlignment(SwingConstants.LEFT); + } else if ("CENTER".equals(val)) { + getComponent().setHorizontalAlignment(SwingConstants.CENTER); + } else if ("RIGHT".equals(val)) { + getComponent().setHorizontalAlignment(SwingConstants.RIGHT); } } + Dimension dim = getComponent().getPreferredSize(); + if ("width".equals(name)) { + dim.width = Integer.parseInt(val); + getComponent().setPreferredSize(dim); + } + if ("height".equals(name)) { + dim.height = Integer.parseInt(val); + getComponent().setPreferredSize(dim); + } } } diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/CenterAdaptType.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/CenterAdaptType.java index 39fcfd5..4e9d4b3 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/CenterAdaptType.java +++ b/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; 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 java.awt.*; @@ -11,24 +15,19 @@ import java.awt.*; * Created by 秃破天际 on 2021/11/1 **/ public class CenterAdaptType extends AbstractLayoutType { + protected JComponent wrapComponent; + @Override 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 - public void layout(Element child,int idx ) { - JComponent component = element.getComponent(); - 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()); - } + public void layout(Element child, int idx) { + wrapComponent.add(child.getWrapper()); } } diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalAdaptType.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalAdaptType.java index c7e68ee..b166c37 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalAdaptType.java +++ b/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.VerticalFlowLayout; +import com.tptj.tool.hg.fineui.swing.element.layout.impl.VerticalLayout; import javax.swing.*; import java.awt.*; @@ -14,7 +15,7 @@ import java.awt.*; public class HorizontalAdaptType extends AbstractLayoutType{ @Override public LayoutManager init() { - return new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true); + return new VerticalLayout(element, VerticalFlowLayout.TOP, 0, 0, true); } @Override diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalType.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalType.java index da0b161..a1e5bb4 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/HorizontalType.java +++ b/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; import com.tptj.tool.hg.fineui.swing.element.Element; +import com.tptj.tool.hg.fineui.swing.element.layout.impl.HorizontalLayout; import javax.swing.*; +import java.awt.*; /** * @author 秃破天际 * @version 10.0 * 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 public void layout(Element child, int idx) { diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalAdaptType.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalAdaptType.java index d7e355e..41939d4 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalAdaptType.java +++ b/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; 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 java.awt.*; /** * @author 秃破天际 @@ -11,11 +15,11 @@ import javax.swing.*; **/ public class VerticalAdaptType extends CenterAdaptType { @Override - public void layout(Element child, int idx ) { - Box box = new Box(BoxLayout.Y_AXIS); - box.add(Box.createVerticalGlue()); - box.add( child.getWrapper() ); - box.add(Box.createVerticalGlue()); - element.getComponent().add(box); + public LayoutManager init() { + wrapComponent = new JPanel(); + wrapComponent.setOpaque(false); + wrapComponent.setLayout(new HorizontalLayout(element, FlowLayout.LEFT, 0, 0)); + element.getComponent().add(wrapComponent); + return new VerticalLayout(element, VerticalFlowLayout.CENTER, 0, 0, true); } } diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalType.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalType.java index a8c3cbb..fdab83d 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalType.java +++ b/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.VerticalFlowLayout; +import com.tptj.tool.hg.fineui.swing.element.layout.impl.VerticalLayout; import java.awt.*; @@ -10,14 +11,14 @@ import java.awt.*; * @version 10.0 * Created by 秃破天际 on 2021/11/1 **/ -public class VerticalType extends AbstractLayoutType{ +public class VerticalType extends AbstractLayoutType { @Override public LayoutManager init() { - return new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true); + return new VerticalLayout(element, VerticalFlowLayout.TOP, 0, 0, true); } @Override public void layout(Element child, int idx) { - element.getComponent().add( child.getWrapper() ); + element.getComponent().add(child.getWrapper()); } } diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/BaseFineUILayout.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/BaseFineUILayout.java index 5356bf1..d3739df 100644 --- a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/BaseFineUILayout.java +++ b/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 static final int NOT_EXIST = -99999; + public static final int MAX_SIZE = 99999; protected Element element; - public BaseFineUILayout(Element element){ + public BaseFineUILayout(Element element) { this.element = element; } @@ -61,16 +62,29 @@ public abstract class BaseFineUILayout implements LayoutManager2 { int p_height = 0; int width = parent.getParent().getWidth(); int height = parent.getParent().getHeight(); - for( Element child : children ){ + for (Element child : children) { 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; } - if( rect.y + rect.height > p_height ){ + if (rect.y + rect.height > p_height) { p_height = rect.y + rect.height; } } - return new Dimension(p_width, p_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 realDim; } @Override @@ -83,13 +97,13 @@ public abstract class BaseFineUILayout implements LayoutManager2 { int width = parent.getWidth(); int height = parent.getHeight(); List children = element.children(); - for( Element child : children ){ + for (Element child : children) { 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); } diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/CenterLayout.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/CenterLayout.java new file mode 100644 index 0000000..893e45a --- /dev/null +++ b/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); + } +} diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/HorizontalLayout.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/HorizontalLayout.java new file mode 100644 index 0000000..fc05311 --- /dev/null +++ b/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); + } +} diff --git a/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/VerticalLayout.java b/src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/impl/VerticalLayout.java new file mode 100644 index 0000000..3163eb5 --- /dev/null +++ b/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); + } +}