|
|
@ -35,6 +35,9 @@ import java.awt.geom.RoundRectangle2D; |
|
|
|
public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
protected static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150); |
|
|
|
protected static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150); |
|
|
|
protected Background background4Painting; // 设计器预览界面中绘制组件背景图
|
|
|
|
protected Background background4Painting; // 设计器预览界面中绘制组件背景图
|
|
|
|
|
|
|
|
protected double backgroundOpacity4Painting; // 设计器预览界面中绘制组件背景图
|
|
|
|
|
|
|
|
protected Background borderImage4Painting; // 设计器预览界面中绘制边框图片
|
|
|
|
|
|
|
|
protected double borderImageOpacity4Painting; |
|
|
|
|
|
|
|
|
|
|
|
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { |
|
|
|
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { |
|
|
|
super(widget, initSize); |
|
|
|
super(widget, initSize); |
|
|
@ -49,9 +52,26 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
return this.background4Painting; |
|
|
|
return this.background4Painting; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setBackground4Painting(Background background4Painting) { |
|
|
|
public double getBackgroundOpacity4Painting() { |
|
|
|
this.background4Painting = background4Painting; |
|
|
|
return backgroundOpacity4Painting; |
|
|
|
this.repaint(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setBackground4Painting(Background background, double opacity) { |
|
|
|
|
|
|
|
this.background4Painting = background; |
|
|
|
|
|
|
|
this.backgroundOpacity4Painting = opacity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Background getBorderImage4Painting() { |
|
|
|
|
|
|
|
return borderImage4Painting; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public double getBorderImageOpacity4Painting() { |
|
|
|
|
|
|
|
return borderImageOpacity4Painting; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setBorderImage4Painting(Background borderImage, double opacity) { |
|
|
|
|
|
|
|
this.borderImage4Painting = borderImage; |
|
|
|
|
|
|
|
this.borderImageOpacity4Painting = opacity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -102,8 +122,13 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.setBorder(border); |
|
|
|
this.setBorder(border); |
|
|
|
|
|
|
|
if (style != null) { |
|
|
|
this.setBackground4Painting(style != null ? style.getBackground() : null); |
|
|
|
this.setBorderImage4Painting(style.getBorderImage(), style.getBorderImageOpacity()); |
|
|
|
|
|
|
|
this.setBackground4Painting(style.getBackground(), style.getAlpha()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.setBorderImage4Painting(null, 0.0); |
|
|
|
|
|
|
|
this.setBackground4Painting(null, 0.0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void clearTitleWidget() { |
|
|
|
private void clearTitleWidget() { |
|
|
@ -183,29 +208,56 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
XCreator titleCreator = titleParent.getTitleCreator(); |
|
|
|
XCreator titleCreator = titleParent.getTitleCreator(); |
|
|
|
XCreator bodyXCreator = titleParent.getBodyCreator(); |
|
|
|
XCreator bodyXCreator = titleParent.getBodyCreator(); |
|
|
|
|
|
|
|
|
|
|
|
Border border = bodyXCreator.getBorder(); |
|
|
|
reshuffleBorderPaintingEffectIfTitleExists(titleParent, titleCreator, bodyXCreator); |
|
|
|
|
|
|
|
reshuffleBackgroundPaintingEffectIfTitleExists(titleParent, titleCreator, bodyXCreator); |
|
|
|
titleParent.setBorder(border); // 容器绘制完整边框
|
|
|
|
|
|
|
|
bodyXCreator.setBorder(BorderFactory.createEmptyBorder()); // body不绘制边框
|
|
|
|
|
|
|
|
titleCreator.setBorder(BorderFactory.createEmptyBorder()); // title绘制底部边框
|
|
|
|
|
|
|
|
if (border instanceof LineBorder) { |
|
|
|
|
|
|
|
Color color = ((LineBorder) border).getLineColor(); |
|
|
|
|
|
|
|
int thickness = ((LineBorder) border).getThickness(); |
|
|
|
|
|
|
|
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); // 容器绘制完整背景
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void reshuffleBorderPaintingEffectIfTitleExists(XWTitleLayout parentCreator, XCreator titleCreator, XCreator bodyCreator) { |
|
|
|
|
|
|
|
Border border = bodyCreator.getBorder(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parentCreator.setBorder(border); // 容器绘制完整边框
|
|
|
|
|
|
|
|
bodyCreator.setBorder(BorderFactory.createEmptyBorder()); // body不绘制边框
|
|
|
|
|
|
|
|
titleCreator.setBorder(BorderFactory.createEmptyBorder()); // title绘制底部边框
|
|
|
|
|
|
|
|
if (border instanceof LineBorder) { |
|
|
|
|
|
|
|
Color color = ((LineBorder) border).getLineColor(); |
|
|
|
|
|
|
|
int thickness = ((LineBorder) border).getThickness(); |
|
|
|
|
|
|
|
titleCreator.setBorder(new BottomLineBorder(color, thickness)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bodyCreator instanceof XBorderStyleWidgetCreator) { |
|
|
|
|
|
|
|
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyCreator; |
|
|
|
|
|
|
|
Background borderImage= styledBodyXCreator.getBorderImage4Painting(); |
|
|
|
|
|
|
|
double opacity = styledBodyXCreator.getBorderImageOpacity4Painting(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
styledBodyXCreator.setBorderImage4Painting(null, 0.0); // body不绘制图片边框
|
|
|
|
|
|
|
|
parentCreator.setBorderImage4Painting(borderImage, opacity); // 容器绘制完整图片边框
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void reshuffleBackgroundPaintingEffectIfTitleExists(XWTitleLayout parentCreator, XCreator titleCreator, XCreator bodyCreator) { |
|
|
|
|
|
|
|
if (titleCreator instanceof XLabel) { |
|
|
|
|
|
|
|
XLabel labelCreator = (XLabel) titleCreator; |
|
|
|
|
|
|
|
Label titleLabel = labelCreator.toData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Background background = titleLabel.getBackground(); |
|
|
|
|
|
|
|
double opacity = titleLabel.getBackgroundOpacity(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
labelCreator.setEnabledBackgroundPainting(false); // 标题不绘制背景
|
|
|
|
|
|
|
|
parentCreator.setTitleBackground4Painting(background, opacity); // 容器绘制完整背景
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bodyCreator instanceof XBorderStyleWidgetCreator) { |
|
|
|
|
|
|
|
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyCreator; |
|
|
|
|
|
|
|
Background background = styledBodyXCreator.getBackground4Painting(); |
|
|
|
|
|
|
|
double opacity = styledBodyXCreator.getBackgroundOpacity4Painting(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
styledBodyXCreator.setBackground4Painting(null, 0.0); // body不绘制背景
|
|
|
|
|
|
|
|
parentCreator.setBodyBackground4Painting(background, opacity); // 容器绘制完整背景
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据当前组件边框裁剪内容,如果当前组件存在圆角,则应当按圆角裁剪内容
|
|
|
|
// 根据当前组件边框裁剪内容,如果当前组件存在圆角,则应当按圆角裁剪内容
|
|
|
|
private void clipByRoundedBorder(Graphics2D g2d) { |
|
|
|
private void clipByRoundedBorder(Graphics2D g2d) { |
|
|
@ -226,10 +278,22 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
public void paintBackground(Graphics2D g2d) { |
|
|
|
public void paintBackground(Graphics2D g2d) { |
|
|
|
Background background4Painting = getBackground4Painting(); |
|
|
|
Background background4Painting = getBackground4Painting(); |
|
|
|
if (background4Painting != null) { |
|
|
|
if (background4Painting != null) { |
|
|
|
BorderPacker style = toData().getBorderStyle(); |
|
|
|
|
|
|
|
Composite oldComposite = g2d.getComposite(); |
|
|
|
Composite oldComposite = g2d.getComposite(); |
|
|
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, style.getAlpha())); |
|
|
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) backgroundOpacity4Painting)); |
|
|
|
background4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight())); |
|
|
|
|
|
|
|
|
|
|
|
Shape shape = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); |
|
|
|
|
|
|
|
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); |
|
|
|
g2d.setComposite(oldComposite); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -243,6 +307,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
public void paint(Graphics g) { |
|
|
|
public void paint(Graphics g) { |
|
|
|
this.clipByRoundedBorder((Graphics2D) g); |
|
|
|
this.clipByRoundedBorder((Graphics2D) g); |
|
|
|
this.paintBackground((Graphics2D) g); |
|
|
|
this.paintBackground((Graphics2D) g); |
|
|
|
|
|
|
|
this.paintBorderImage((Graphics2D) g); |
|
|
|
this.paintForeground((Graphics2D) g); |
|
|
|
this.paintForeground((Graphics2D) g); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -293,7 +358,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(getLineColor()); |
|
|
|
g2d.setColor(getLineColor()); |
|
|
|
g2d.setStroke(new BasicStroke(getThickness())); |
|
|
|
g2d.setStroke(new BasicStroke(getThickness() * 2)); |
|
|
|
g2d.drawLine(0, height, width, height); |
|
|
|
g2d.drawLine(0, height, width, height); |
|
|
|
|
|
|
|
|
|
|
|
g2d.setStroke(oldStroke); |
|
|
|
g2d.setStroke(oldStroke); |
|
|
|