10.0 #1

Merged
guy merged 2 commits from guy/open-fineui-swing:10.0 into 10.0 3 years ago
  1. 3
      src/main/java/com/tptj/tool/hg/fineui/swing/FineUIEngine.java
  2. 24
      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. 15
      src/main/java/com/tptj/tool/hg/fineui/swing/element/LabelElement.java
  5. 25
      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. 3
      src/main/java/com/tptj/tool/hg/fineui/swing/element/layout/VerticalType.java
  10. 16
      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

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

24
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;
@ -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;
@ -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);
@ -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

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

15
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 秃破天际
@ -26,6 +27,7 @@ public class LabelElement extends AbstractElement<UILabel> {
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);
@ -39,5 +41,18 @@ public class LabelElement extends AbstractElement<UILabel> {
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);
}
}
} }
} }

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

3
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.*;
@ -13,7 +14,7 @@ import java.awt.*;
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

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

@ -13,6 +13,7 @@ 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) {
@ -70,8 +71,21 @@ public abstract class BaseFineUILayout implements LayoutManager2 {
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) {
@ -85,7 +99,7 @@ public abstract class BaseFineUILayout implements LayoutManager2 {
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);
} }
} }

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