@ -52,33 +52,26 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
return this . background4Painting ;
return this . background4Painting ;
}
}
public void setBackground4Painting ( Background background4Painting ) {
this . background4Painting = background4Painting ;
this . repaint ( ) ;
}
public double getBackgroundOpacity4Painting ( ) {
public double getBackgroundOpacity4Painting ( ) {
return backgroundOpacity4Painting ;
return backgroundOpacity4Painting ;
}
}
public void setBackgroundOpacity4Painting ( double backgroundOpacity4Painting ) {
public void setBackground4Painting ( Background background , double opacity ) {
this . backgroundOpacity4Painting = backgroundOpacity4Painting ;
this . background4Painting = background ;
this . backgroundOpacity4Painting = opacity ;
}
}
public Background getBorderImage4Painting ( ) {
public Background getBorderImage4Painting ( ) {
return borderImage4Painting ;
return borderImage4Painting ;
}
}
public void setBorderImage4Painting ( Background borderImage4Painting ) {
this . borderImage4Painting = borderImage4Painting ;
}
public double getBorderImageOpacity4Painting ( ) {
public double getBorderImageOpacity4Painting ( ) {
return borderImageOpacity4Painting ;
return borderImageOpacity4Painting ;
}
}
public void setBorderImageOpacity4Painting ( double borderImageOpacity4Painting ) {
public void setBorderImage4Painting ( Background borderImage , double opacity ) {
this . borderImageOpacity4Painting = borderImageOpacity4Painting ;
this . borderImage4Painting = borderImage ;
this . borderImageOpacity4Painting = opacity ;
}
}
/ * *
/ * *
@ -129,11 +122,13 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
}
}
this . setBorder ( border ) ;
this . setBorder ( border ) ;
this . setBorderImage4Painting ( style ! = null ? style . getBorderImage ( ) : null ) ;
if ( style ! = null ) {
this . setBorderImageOpacity4Painting ( style ! = null ? style . getBorderImageOpacity ( ) : 0 . 0 ) ;
this . setBorderImage4Painting ( style . getBorderImage ( ) , style . getBorderImageOpacity ( ) ) ;
this . setBackground4Painting ( style . getBackground ( ) , style . getAlpha ( ) ) ;
this . setBackground4Painting ( style ! = null ? style . getBackground ( ) : null ) ;
} else {
this . setBackgroundOpacity4Painting ( style ! = null ? style . getAlpha ( ) : 0 . 0 ) ;
this . setBorderImage4Painting ( null , 0 . 0 ) ;
this . setBackground4Painting ( null , 0 . 0 ) ;
}
}
}
private void clearTitleWidget ( ) {
private void clearTitleWidget ( ) {
@ -213,42 +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 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 ) ;
}
}
}
}
}
}
}
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 ) {
@ -273,16 +282,6 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
g2d . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_ATOP , ( float ) backgroundOpacity4Painting ) ) ;
g2d . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_ATOP , ( float ) backgroundOpacity4Painting ) ) ;
Shape shape = new Rectangle2D . Double ( 0 , 0 , getWidth ( ) , getHeight ( ) ) ;
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 ) ;
background4Painting . paint ( g2d , shape ) ;
g2d . setComposite ( oldComposite ) ;
g2d . setComposite ( oldComposite ) ;