Browse Source

feature:布局支持滚动条

pull/1/head
guy 3 years ago
parent
commit
87d937dcfd
  1. 39
      src/main/java/com/tptj/tool/hg/fineui/swing/FineUIEngine.java
  2. 64
      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. 31
      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. 30
      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

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

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

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();
JComponent getWrapper();
boolean hasScrollbar();
Map<String,Object> getStyle();
int getRectStyleAttr( String name,int max, int min );
@ -51,8 +53,8 @@ public interface Element<T extends JComponent> {
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();

31
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<UILabel> {
}
@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);
}
}
}

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

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.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

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

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

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

30
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<AbstractElement> 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);
}

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