|
|
@ -186,10 +186,10 @@ public class FineUIUtils { |
|
|
|
* @param background 背景色 |
|
|
|
* @param background 背景色 |
|
|
|
* @param width 宽度 |
|
|
|
* @param width 宽度 |
|
|
|
* @param height 高度 |
|
|
|
* @param height 高度 |
|
|
|
* @param radius 圆角 |
|
|
|
* @param arc 圆角 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void paintWithComposite(Graphics g, Composite composite, Color background, |
|
|
|
public static void paintWithComposite(Graphics g, Composite composite, Color background, |
|
|
|
int width, int height, int radius) { |
|
|
|
int width, int height, int arc) { |
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
|
|
|
|
|
|
|
FlatUIUtils.setRenderingHints(g2d); |
|
|
|
FlatUIUtils.setRenderingHints(g2d); |
|
|
@ -197,7 +197,7 @@ public class FineUIUtils { |
|
|
|
g2d.setComposite(composite); |
|
|
|
g2d.setComposite(composite); |
|
|
|
|
|
|
|
|
|
|
|
g2d.setColor(background); |
|
|
|
g2d.setColor(background); |
|
|
|
g2d.fill(new RoundRectangle2D.Float(0, 0, width, height, radius, radius)); |
|
|
|
g2d.fill(new RoundRectangle2D.Float(0, 0, width, height, arc, arc)); |
|
|
|
g2d.setComposite(oldComposite); |
|
|
|
g2d.setComposite(oldComposite); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -247,14 +247,14 @@ public class FineUIUtils { |
|
|
|
case LEFT: { |
|
|
|
case LEFT: { |
|
|
|
path2D.append(createLeftRoundRectangle(x, y, width, height, arc), false); |
|
|
|
path2D.append(createLeftRoundRectangle(x, y, width, height, arc), false); |
|
|
|
path2D.append(createLeftRoundRectangle(x + t, y + t, |
|
|
|
path2D.append(createLeftRoundRectangle(x + t, y + t, |
|
|
|
width - (closedPath ? t2x : t), height - t2x, arc - t), false); |
|
|
|
width - (closedPath ? t2x : t), height - t2x, arc - t2x), false); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case RIGHT: |
|
|
|
case RIGHT: |
|
|
|
default: { |
|
|
|
default: { |
|
|
|
path2D.append(createRightRoundRectangle(x, y, width, height, arc), false); |
|
|
|
path2D.append(createRightRoundRectangle(x, y, width, height, arc), false); |
|
|
|
path2D.append(createRightRoundRectangle(x + (closedPath ? t : 0), y + t, |
|
|
|
path2D.append(createRightRoundRectangle(x + (closedPath ? t : 0), y + t, |
|
|
|
width - (closedPath ? t2x : t), height - t2x, arc - t), false); |
|
|
|
width - (closedPath ? t2x : t), height - t2x, arc - t2x), false); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -280,12 +280,18 @@ public class FineUIUtils { |
|
|
|
float t2x = t * 2; |
|
|
|
float t2x = t * 2; |
|
|
|
Path2D path2D = new Path2D.Float(Path2D.WIND_EVEN_ODD); |
|
|
|
Path2D path2D = new Path2D.Float(Path2D.WIND_EVEN_ODD); |
|
|
|
path2D.append(createTopRoundRectangle(x, y, width, height, arc), false); |
|
|
|
path2D.append(createTopRoundRectangle(x, y, width, height, arc), false); |
|
|
|
path2D.append(createTopRoundRectangle(x + t, y + t, width - t2x, height - t, arc - t), false); |
|
|
|
path2D.append(createTopRoundRectangle(x + t, y + t, width - t2x, height - t, arc - t2x), false); |
|
|
|
g2.fill(path2D); |
|
|
|
g2.fill(path2D); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 创建一个部分圆角的矩形路径 |
|
|
|
* 创建一个部分圆角的矩形路径 |
|
|
|
|
|
|
|
* <p> |
|
|
|
|
|
|
|
* 注意: |
|
|
|
|
|
|
|
* 在swing中,UI的样式的 arc 数值是直径,而 css 中 border-radius 为半径, |
|
|
|
|
|
|
|
* 因此我们配置的 arc 全部为 border-radius 的2倍。但是使用 Path2D 绘制时, |
|
|
|
|
|
|
|
* 绘制方式其实是使用半径来进行计算的,为了保持调用一致,对外 API 还是以 arc |
|
|
|
|
|
|
|
* 的形式,因此方法内部需要对 arc 进行取半处理, |
|
|
|
* |
|
|
|
* |
|
|
|
* @param x x坐标 |
|
|
|
* @param x x坐标 |
|
|
|
* @param y y坐标 |
|
|
|
* @param y y坐标 |
|
|
@ -299,16 +305,20 @@ public class FineUIUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Path2D createPartRoundRectangle(double x, double y, double width, double height, |
|
|
|
public static Path2D createPartRoundRectangle(double x, double y, double width, double height, |
|
|
|
double arcTopLeft, double arcTopRight, double arcBottomRight, double arcBottomLeft) { |
|
|
|
double arcTopLeft, double arcTopRight, double arcBottomRight, double arcBottomLeft) { |
|
|
|
Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD, 7); |
|
|
|
double radiusTopLeft = arcTopLeft / 2; |
|
|
|
path.moveTo(x + arcTopLeft, y); |
|
|
|
double radiusTopRight = arcTopRight / 2; |
|
|
|
path.lineTo(x + width - arcTopRight, y); |
|
|
|
double radiusBottomLeft = arcBottomLeft / 2; |
|
|
|
path.quadTo(x + width, y, x + width, y + arcTopRight); |
|
|
|
double radiusBottomRight = arcBottomRight / 2; |
|
|
|
path.lineTo(x + width, y + height - arcBottomRight); |
|
|
|
Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD, 10); |
|
|
|
path.quadTo(x + width, y + height, x + width - arcBottomRight, y + height); |
|
|
|
path.moveTo(x + radiusTopLeft, y); |
|
|
|
path.lineTo(x + arcBottomLeft, y + height); |
|
|
|
path.lineTo(x + width - radiusTopRight, y); |
|
|
|
path.quadTo(x, y + height, x, y + height - arcBottomLeft); |
|
|
|
path.quadTo(x + width, y, x + width, y + radiusTopRight); |
|
|
|
path.lineTo(x, y + arcTopLeft); |
|
|
|
path.lineTo(x + width, y + height - radiusBottomRight); |
|
|
|
path.quadTo(x, y, x + arcTopLeft, y); |
|
|
|
path.quadTo(x + width, y + height, x + width - radiusBottomRight, y + height); |
|
|
|
|
|
|
|
path.lineTo(x + radiusBottomLeft, y + height); |
|
|
|
|
|
|
|
path.quadTo(x, y + height, x, y + height - radiusBottomLeft); |
|
|
|
|
|
|
|
path.lineTo(x, y + radiusTopLeft); |
|
|
|
|
|
|
|
path.quadTo(x, y, x + radiusTopLeft, y); |
|
|
|
path.closePath(); |
|
|
|
path.closePath(); |
|
|
|
return path; |
|
|
|
return path; |
|
|
|
} |
|
|
|
} |
|
|
|