|
|
|
@ -35,6 +35,9 @@ import java.awt.geom.RoundRectangle2D;
|
|
|
|
|
public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
|
protected static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150); |
|
|
|
|
protected Background background4Painting; // 设计器预览界面中绘制组件背景图
|
|
|
|
|
protected double backgroundOpacity4Painting; // 设计器预览界面中绘制组件背景图
|
|
|
|
|
protected Background borderImage4Painting; // 设计器预览界面中绘制边框图片
|
|
|
|
|
protected double borderImageOpacity4Painting; |
|
|
|
|
|
|
|
|
|
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { |
|
|
|
|
super(widget, initSize); |
|
|
|
@ -54,6 +57,30 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
|
|
|
|
|
this.repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public double getBackgroundOpacity4Painting() { |
|
|
|
|
return backgroundOpacity4Painting; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setBackgroundOpacity4Painting(double backgroundOpacity4Painting) { |
|
|
|
|
this.backgroundOpacity4Painting = backgroundOpacity4Painting; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Background getBorderImage4Painting() { |
|
|
|
|
return borderImage4Painting; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setBorderImage4Painting(Background borderImage4Painting) { |
|
|
|
|
this.borderImage4Painting = borderImage4Painting; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public double getBorderImageOpacity4Painting() { |
|
|
|
|
return borderImageOpacity4Painting; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setBorderImageOpacity4Painting(double borderImageOpacity4Painting) { |
|
|
|
|
this.borderImageOpacity4Painting = borderImageOpacity4Painting; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 返回容器对应的widget |
|
|
|
|
* @return 同上 |
|
|
|
@ -102,8 +129,11 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setBorder(border); |
|
|
|
|
this.setBorderImage4Painting(style != null ? style.getBorderImage() : null); |
|
|
|
|
this.setBorderImageOpacity4Painting(style != null ? style.getBorderImageOpacity() : 0.0); |
|
|
|
|
|
|
|
|
|
this.setBackground4Painting(style != null ? style.getBackground() : null); |
|
|
|
|
this.setBackgroundOpacity4Painting(style != null ? style.getAlpha() : 0.0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void clearTitleWidget() { |
|
|
|
@ -194,14 +224,27 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
|
|
|
|
|
titleCreator.setBorder(new BottomLineBorder(color, thickness)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 主体背景的生效范围暂时保持原样,不作用于包含标题区域的整体范围内
|
|
|
|
|
// if (bodyXCreator instanceof XBorderStyleWidgetCreator) {
|
|
|
|
|
// XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator;
|
|
|
|
|
// Background background4Painting = styledBodyXCreator.getBackground4Painting();
|
|
|
|
|
//
|
|
|
|
|
// styledBodyXCreator.setBackground4Painting(null); // body不绘制背景
|
|
|
|
|
// titleParent.setBackground4Painting(background4Painting); // 容器绘制完整背景
|
|
|
|
|
// }
|
|
|
|
|
if (bodyXCreator instanceof XBorderStyleWidgetCreator) { |
|
|
|
|
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator; |
|
|
|
|
Background borderImage4Painting = styledBodyXCreator.getBorderImage4Painting(); |
|
|
|
|
double opacity = styledBodyXCreator.getBorderImageOpacity4Painting(); |
|
|
|
|
|
|
|
|
|
styledBodyXCreator.setBorderImage4Painting(null); // body不绘制图片边框
|
|
|
|
|
styledBodyXCreator.setBorderImageOpacity4Painting(0.0); |
|
|
|
|
titleParent.setBorderImage4Painting(borderImage4Painting); // 容器绘制完整图片边框
|
|
|
|
|
titleParent.setBorderImageOpacity4Painting(opacity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (bodyXCreator instanceof XBorderStyleWidgetCreator) { |
|
|
|
|
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator; |
|
|
|
|
Background background4Painting = styledBodyXCreator.getBackground4Painting(); |
|
|
|
|
double opacity = styledBodyXCreator.getBackgroundOpacity4Painting(); |
|
|
|
|
|
|
|
|
|
styledBodyXCreator.setBackground4Painting(null); // body不绘制背景
|
|
|
|
|
styledBodyXCreator.setBackgroundOpacity4Painting(0.0); |
|
|
|
|
titleParent.setBackground4Painting(background4Painting); // 容器绘制完整背景
|
|
|
|
|
titleParent.setBackgroundOpacity4Painting(opacity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -226,10 +269,32 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
|
|
|
|
|
public void paintBackground(Graphics2D g2d) { |
|
|
|
|
Background background4Painting = getBackground4Painting(); |
|
|
|
|
if (background4Painting != null) { |
|
|
|
|
BorderPacker style = toData().getBorderStyle(); |
|
|
|
|
Composite oldComposite = g2d.getComposite(); |
|
|
|
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, style.getAlpha())); |
|
|
|
|
background4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight())); |
|
|
|
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) backgroundOpacity4Painting)); |
|
|
|
|
|
|
|
|
|
Shape shape = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); |
|
|
|
|
if (this instanceof XWTitleLayout) { |
|
|
|
|
// 兼容性考虑,组件样式背景不作用在标题范围内,只作用在控件整体,但同时不能遮挡作用于整体的边框图片
|
|
|
|
|
// 所以考虑样式背景与边框图片都由XWTitleLayout绘制,但样式背景要向下偏移标题栏的高度
|
|
|
|
|
XWTitleLayout titleParent = (XWTitleLayout) this; |
|
|
|
|
if (getComponentCount() > 1) { |
|
|
|
|
XCreator titleCreator = titleParent.getTitleCreator(); |
|
|
|
|
int titleHeight = titleCreator != null ? titleCreator.getHeight() : 0; |
|
|
|
|
shape = new Rectangle2D.Double(0, titleHeight, getWidth(), getHeight() - titleHeight); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
background4Painting.paint(g2d, shape); |
|
|
|
|
|
|
|
|
|
g2d.setComposite(oldComposite); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void paintBorderImage(Graphics2D g2d) { |
|
|
|
|
Background borderImage4Painting = getBorderImage4Painting(); |
|
|
|
|
if (borderImage4Painting != null) { |
|
|
|
|
Composite oldComposite = g2d.getComposite(); |
|
|
|
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) borderImageOpacity4Painting)); |
|
|
|
|
borderImage4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight())); |
|
|
|
|
g2d.setComposite(oldComposite); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -243,6 +308,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
|
|
|
|
|
public void paint(Graphics g) { |
|
|
|
|
this.clipByRoundedBorder((Graphics2D) g); |
|
|
|
|
this.paintBackground((Graphics2D) g); |
|
|
|
|
this.paintBorderImage((Graphics2D) g); |
|
|
|
|
this.paintForeground((Graphics2D) g); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|